{"action":"created","issue":{"url":"https://api.github.com/repos/glguy/utf8-string/issues/12","labels_url":"https://api.github.com/repos/glguy/utf8-string/issues/12/labels{/name}","comments_url":"https://api.github.com/repos/glguy/utf8-string/issues/12/comments","events_url":"https://api.github.com/repos/glguy/utf8-string/issues/12/events","html_url":"https://github.com/glguy/utf8-string/issues/12","id":102131745,"number":12,"title":"Optimise Data.ByteString.Lazy.UTF8.fromString","user":{"login":"ndmitchell","id":1651197,"avatar_url":"https://avatars.githubusercontent.com/u/1651197?v=3","gravatar_id":"","url":"https://api.github.com/users/ndmitchell","html_url":"https://github.com/ndmitchell","followers_url":"https://api.github.com/users/ndmitchell/followers","following_url":"https://api.github.com/users/ndmitchell/following{/other_user}","gists_url":"https://api.github.com/users/ndmitchell/gists{/gist_id}","starred_url":"https://api.github.com/users/ndmitchell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ndmitchell/subscriptions","organizations_url":"https://api.github.com/users/ndmitchell/orgs","repos_url":"https://api.github.com/users/ndmitchell/repos","events_url":"https://api.github.com/users/ndmitchell/events{/privacy}","received_events_url":"https://api.github.com/users/ndmitchell/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-08-20T12:51:04Z","updated_at":"2015-08-20T21:50:59Z","closed_at":null,"body":"In benchmarking Hoogle I found that Lazy.UTF8.fromString was a bottleneck, so I wrote an optimised version. It's at https://github.com/ndmitchell/hoogle/blob/master/src/General/Str.hs#L90. QuickCheck shows it to be equivalent, at least as far as the QuickCheck String generator works. My benchmarks suggest my version is more than twice as fast on my data, but if you want to take this version, it should be properly benchmarked. Mine has the advantage of being lazy (I don't think yours is, but I'm not sure). The only downside is that it allocates 1024 byte bytestrings each time, so for the final chunk or for short bytestrings there will be some memory wastage - but that could be avoided with a BS.copy."},"comment":{"url":"https://api.github.com/repos/glguy/utf8-string/issues/comments/133188392","html_url":"https://github.com/glguy/utf8-string/issues/12#issuecomment-133188392","issue_url":"https://api.github.com/repos/glguy/utf8-string/issues/12","id":133188392,"user":{"login":"glguy","id":12164,"avatar_url":"https://avatars.githubusercontent.com/u/12164?v=3","gravatar_id":"","url":"https://api.github.com/users/glguy","html_url":"https://github.com/glguy","followers_url":"https://api.github.com/users/glguy/followers","following_url":"https://api.github.com/users/glguy/following{/other_user}","gists_url":"https://api.github.com/users/glguy/gists{/gist_id}","starred_url":"https://api.github.com/users/glguy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glguy/subscriptions","organizations_url":"https://api.github.com/users/glguy/orgs","repos_url":"https://api.github.com/users/glguy/repos","events_url":"https://api.github.com/users/glguy/events{/privacy}","received_events_url":"https://api.github.com/users/glguy/received_events","type":"User","site_admin":false},"created_at":"2015-08-20T21:50:59Z","updated_at":"2015-08-20T21:50:59Z","body":"I'd be happy to merge in code to make the common case for encoding UTF-8 faster.\r\n\r\nThe existing `fromString` is lazy as it's simply implemented by encoding to a String first (which is lazy) and then calling lazy bytestring's `pack` which lazily produces chunks (which grow by a factor of 2 up to the smallChunkSize)"}}