{"action":"created","issue":{"url":"https://api.github.com/repos/google/flatbuffers/issues/3850","repository_url":"https://api.github.com/repos/google/flatbuffers","labels_url":"https://api.github.com/repos/google/flatbuffers/issues/3850/labels{/name}","comments_url":"https://api.github.com/repos/google/flatbuffers/issues/3850/comments","events_url":"https://api.github.com/repos/google/flatbuffers/issues/3850/events","html_url":"https://github.com/google/flatbuffers/pull/3850","id":148907263,"number":3850,"title":"Fix for #3849","user":{"login":"pjulien","id":673277,"avatar_url":"https://avatars.githubusercontent.com/u/673277?v=3","gravatar_id":"","url":"https://api.github.com/users/pjulien","html_url":"https://github.com/pjulien","followers_url":"https://api.github.com/users/pjulien/followers","following_url":"https://api.github.com/users/pjulien/following{/other_user}","gists_url":"https://api.github.com/users/pjulien/gists{/gist_id}","starred_url":"https://api.github.com/users/pjulien/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pjulien/subscriptions","organizations_url":"https://api.github.com/users/pjulien/orgs","repos_url":"https://api.github.com/users/pjulien/repos","events_url":"https://api.github.com/users/pjulien/events{/privacy}","received_events_url":"https://api.github.com/users/pjulien/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-04-17T00:53:46Z","updated_at":"2016-04-22T18:42:19Z","closed_at":"2016-04-22T18:42:14Z","pull_request":{"url":"https://api.github.com/repos/google/flatbuffers/pulls/3850","html_url":"https://github.com/google/flatbuffers/pull/3850","diff_url":"https://github.com/google/flatbuffers/pull/3850.diff","patch_url":"https://github.com/google/flatbuffers/pull/3850.patch"},"body":"This avoids the following allocations over repeated use:\r\n\r\n- A ``CharsetEncoder``\r\n- A byte array to contain the contents of the string\r\n- A wrapper, via ``ByteBuffer#wrap``, for the previously mentioned byte\r\n  array\r\n\r\nThis also removes a copy of the temporary byte array.  This extra copy\r\nis needed because ``String#getBytes`` returns a byte array and its\r\nlength must match the exact size of the contents.\r\n\r\nThis implementation requires that the builder retain a ``ByteBuffer``\r\nand ``CharEncoder``.  This is considered slower only for users that\r\nwill only allocate a single string in their buffers or none at all.\r\n\r\nThe improvement is especially potent if the builder is constantly reused\r\nby its caller.  This also eliminates the penalty for users that do not\r\nuse strings at all since the cost of allocating these fields is\r\nnow amortized.\r\n\r\nThe only allocation left in this code is a ``CharBuffer`` wrapper.  It's\r\npossible to eliminate this allocation using an additional copy but need\r\nfurther profiling to see which is the bigger problem."},"comment":{"url":"https://api.github.com/repos/google/flatbuffers/issues/comments/213548728","html_url":"https://github.com/google/flatbuffers/pull/3850#issuecomment-213548728","issue_url":"https://api.github.com/repos/google/flatbuffers/issues/3850","id":213548728,"user":{"login":"gwvo","id":6145400,"avatar_url":"https://avatars.githubusercontent.com/u/6145400?v=3","gravatar_id":"","url":"https://api.github.com/users/gwvo","html_url":"https://github.com/gwvo","followers_url":"https://api.github.com/users/gwvo/followers","following_url":"https://api.github.com/users/gwvo/following{/other_user}","gists_url":"https://api.github.com/users/gwvo/gists{/gist_id}","starred_url":"https://api.github.com/users/gwvo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gwvo/subscriptions","organizations_url":"https://api.github.com/users/gwvo/orgs","repos_url":"https://api.github.com/users/gwvo/repos","events_url":"https://api.github.com/users/gwvo/events{/privacy}","received_events_url":"https://api.github.com/users/gwvo/received_events","type":"User","site_admin":false},"created_at":"2016-04-22T18:42:19Z","updated_at":"2016-04-22T18:42:19Z","body":"Thanks!"}}