{"action":"created","issue":{"url":"https://api.github.com/repos/JasperFx/marten/issues/640","repository_url":"https://api.github.com/repos/JasperFx/marten","labels_url":"https://api.github.com/repos/JasperFx/marten/issues/640/labels{/name}","comments_url":"https://api.github.com/repos/JasperFx/marten/issues/640/comments","events_url":"https://api.github.com/repos/JasperFx/marten/issues/640/events","html_url":"https://github.com/JasperFx/marten/issues/640","id":195841081,"number":640,"title":"Buffer pooling for marten","user":{"login":"Scooletz","id":519707,"avatar_url":"https://avatars.githubusercontent.com/u/519707?v=3","gravatar_id":"","url":"https://api.github.com/users/Scooletz","html_url":"https://github.com/Scooletz","followers_url":"https://api.github.com/users/Scooletz/followers","following_url":"https://api.github.com/users/Scooletz/following{/other_user}","gists_url":"https://api.github.com/users/Scooletz/gists{/gist_id}","starred_url":"https://api.github.com/users/Scooletz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Scooletz/subscriptions","organizations_url":"https://api.github.com/users/Scooletz/orgs","repos_url":"https://api.github.com/users/Scooletz/repos","events_url":"https://api.github.com/users/Scooletz/events{/privacy}","received_events_url":"https://api.github.com/users/Scooletz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-12-15T15:53:09Z","updated_at":"2016-12-15T19:49:13Z","closed_at":null,"body":"Below you can find a description of providing buffer pooling for Marten.\r\n\r\n---\r\n\r\nCurrently, `EventStreamAppender` uses `JsonBodies` func to append bodies as an array of strings ([here](https://github.com/JasperFx/marten/blob/2f18d09fa2034cbc647f48a74bbf3bbb8ea51116/src/Marten/Events/EventStreamAppender.cs#L37)).\r\nAccording to `Npgsql` driver, it's possible to pass a `char[]` instead of string and use the parameter size to limit the length of the appended data ([here](https://github.com/npgsql/npgsql/blob/4ef74fa78cffbb4b1fdac00601d0ee5bff5e242b/src/Npgsql/TypeHandlers/TextHandler.cs#L269-L276). \r\n\r\nWe can't use it as we pass the array parameter, but we could \r\n- enable passing `ArraySegment<char>` as `NpgsqlDbType.Jsonb` in Npgsql driver first\r\n- enable serializers to serialize to a predefined `char[]` (+ possibly reallocation if needed)\r\n- pass result `ArraySegment<char>` below.\r\n\r\nHaving this, we could leverage that for other operations, like storing documents (`DocJsonBodyArgument` uses serializer as well). Actually, **we could start with docs first** as they issue a single `Jsonb` parameter (hence, we can use `Size`) and later, decide do we want it for events.\r\n\r\nI'm aware that these allocations are short living. On the other hand we can't tell is it worth it before trying it out.\r\n\r\nWhat do you think?"},"comment":{"url":"https://api.github.com/repos/JasperFx/marten/issues/comments/267425628","html_url":"https://github.com/JasperFx/marten/issues/640#issuecomment-267425628","issue_url":"https://api.github.com/repos/JasperFx/marten/issues/640","id":267425628,"user":{"login":"jeremydmiller","id":179211,"avatar_url":"https://avatars.githubusercontent.com/u/179211?v=3","gravatar_id":"","url":"https://api.github.com/users/jeremydmiller","html_url":"https://github.com/jeremydmiller","followers_url":"https://api.github.com/users/jeremydmiller/followers","following_url":"https://api.github.com/users/jeremydmiller/following{/other_user}","gists_url":"https://api.github.com/users/jeremydmiller/gists{/gist_id}","starred_url":"https://api.github.com/users/jeremydmiller/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeremydmiller/subscriptions","organizations_url":"https://api.github.com/users/jeremydmiller/orgs","repos_url":"https://api.github.com/users/jeremydmiller/repos","events_url":"https://api.github.com/users/jeremydmiller/events{/privacy}","received_events_url":"https://api.github.com/users/jeremydmiller/received_events","type":"User","site_admin":false},"created_at":"2016-12-15T19:49:13Z","updated_at":"2016-12-15T19:49:13Z","body":"@Scooletz It's a little bit related to https://github.com/JasperFx/marten/issues/610. I know that we're doing more allocations than is strictly necessary internally in Marten. I chickened out of trying to do this for 1.2, but I'd like to see this happen. \r\n\r\nHey, in a busy system, this might be well worth the effort. I got stopped last time on the identity map abstractions, but that's a problem that we can beat."}}
{"actor":{"display_login":"jeremydmiller"}}