{"action":"created","issue":{"url":"https://api.github.com/repos/rharriso/PorterStemmer/issues/1","repository_url":"https://api.github.com/repos/rharriso/PorterStemmer","labels_url":"https://api.github.com/repos/rharriso/PorterStemmer/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/rharriso/PorterStemmer/issues/1/comments","events_url":"https://api.github.com/repos/rharriso/PorterStemmer/issues/1/events","html_url":"https://github.com/rharriso/PorterStemmer/pull/1","id":133695114,"number":1,"title":"some potential improvements","user":{"login":"John-Colvin","id":1867189,"avatar_url":"https://avatars.githubusercontent.com/u/1867189?v=3","gravatar_id":"","url":"https://api.github.com/users/John-Colvin","html_url":"https://github.com/John-Colvin","followers_url":"https://api.github.com/users/John-Colvin/followers","following_url":"https://api.github.com/users/John-Colvin/following{/other_user}","gists_url":"https://api.github.com/users/John-Colvin/gists{/gist_id}","starred_url":"https://api.github.com/users/John-Colvin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/John-Colvin/subscriptions","organizations_url":"https://api.github.com/users/John-Colvin/orgs","repos_url":"https://api.github.com/users/John-Colvin/repos","events_url":"https://api.github.com/users/John-Colvin/events{/privacy}","received_events_url":"https://api.github.com/users/John-Colvin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-02-15T11:56:14Z","updated_at":"2016-02-15T11:58:48Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/rharriso/PorterStemmer/pulls/1","html_url":"https://github.com/rharriso/PorterStemmer/pull/1","diff_url":"https://github.com/rharriso/PorterStemmer/pull/1.diff","patch_url":"https://github.com/rharriso/PorterStemmer/pull/1.patch"},"body":"Hi, saw your article and saw the code, but was disappointed to see `D` not performing as well as I expected. However, with some small modifications, I can easily get it down to 0.85s per iteration on my macbook pro using `ldc2`.\r\n\r\nThe rearrangement commit just makes it easier to test an optimised build (`dub` doesn't have a unittest-release setting, see https://github.com/D-Programming-Language/dub/issues/747), as well as being a bit neater.\r\n\r\nChanges that are for style:\r\n* use slicing instead of modifying `.length`\r\n* `for` -> `foreach`\r\n\r\nChanges for performance:\r\n* use an `appender` instead of raw appending.\r\n* disable GC collections, those millions of small allocations from all the stuff like `s ~= \"e\"` are a nightmare for the GC. Note we are still collecting the memory in the end (and including that time in the benchmark).\r\n* not benchmarked, but writing to a file by calling `append` for each element is very slow, so I use `std.stdio.File.write` with `std.algorithm.joiner` instead.\r\n\r\nI think there is still a lot more performance to be got. A few suggestions:\r\n* This is all ASCII, yes? functions like replaceInPlace can't assume this for strings, you may get better performance using `std.utf.byCodeUnit` or casting to `ubyte[]` (remember `string` is `immutable(char)[]`, so the correct cast would be to `immutable(ubyte)[]`)\r\n* Using a mutable string buffer instead of immutable would allow you to do a lot more in-place and lot less `~=`, which is likely a big performance cost. If you like using appending in the body of the code for clarity, you could make a custom string type that manually maintains the buffer and overloads `opOpAssign(string op : \"~\")` and/or try using `std.array.appender` with its `reserve` and `strinkTo` methods to achieve the same thing."},"comment":{"url":"https://api.github.com/repos/rharriso/PorterStemmer/issues/comments/184180513","html_url":"https://github.com/rharriso/PorterStemmer/pull/1#issuecomment-184180513","issue_url":"https://api.github.com/repos/rharriso/PorterStemmer/issues/1","id":184180513,"user":{"login":"John-Colvin","id":1867189,"avatar_url":"https://avatars.githubusercontent.com/u/1867189?v=3","gravatar_id":"","url":"https://api.github.com/users/John-Colvin","html_url":"https://github.com/John-Colvin","followers_url":"https://api.github.com/users/John-Colvin/followers","following_url":"https://api.github.com/users/John-Colvin/following{/other_user}","gists_url":"https://api.github.com/users/John-Colvin/gists{/gist_id}","starred_url":"https://api.github.com/users/John-Colvin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/John-Colvin/subscriptions","organizations_url":"https://api.github.com/users/John-Colvin/orgs","repos_url":"https://api.github.com/users/John-Colvin/repos","events_url":"https://api.github.com/users/John-Colvin/events{/privacy}","received_events_url":"https://api.github.com/users/John-Colvin/received_events","type":"User","site_admin":false},"created_at":"2016-02-15T11:58:48Z","updated_at":"2016-02-15T11:58:48Z","body":"P.S. if you somehow don't use the builtin `~=` inside `stem`, you will likely not be using the GC at all and will be able to dispense with all the `disable`/`enable`/`collect` stuff."}}