{"action":"created","issue":{"url":"https://api.github.com/repos/munificent/wren/issues/381","repository_url":"https://api.github.com/repos/munificent/wren","labels_url":"https://api.github.com/repos/munificent/wren/issues/381/labels{/name}","comments_url":"https://api.github.com/repos/munificent/wren/issues/381/comments","events_url":"https://api.github.com/repos/munificent/wren/issues/381/events","html_url":"https://github.com/munificent/wren/pull/381","id":165470846,"number":381,"title":"Implement String indexOf(needle, startIndex)","user":{"login":"underscorediscovery","id":236374,"avatar_url":"https://avatars.githubusercontent.com/u/236374?v=3","gravatar_id":"","url":"https://api.github.com/users/underscorediscovery","html_url":"https://github.com/underscorediscovery","followers_url":"https://api.github.com/users/underscorediscovery/followers","following_url":"https://api.github.com/users/underscorediscovery/following{/other_user}","gists_url":"https://api.github.com/users/underscorediscovery/gists{/gist_id}","starred_url":"https://api.github.com/users/underscorediscovery/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/underscorediscovery/subscriptions","organizations_url":"https://api.github.com/users/underscorediscovery/orgs","repos_url":"https://api.github.com/users/underscorediscovery/repos","events_url":"https://api.github.com/users/underscorediscovery/events{/privacy}","received_events_url":"https://api.github.com/users/underscorediscovery/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-07-14T03:56:31Z","updated_at":"2016-08-04T07:53:32Z","closed_at":"2016-08-04T05:19:43Z","pull_request":{"url":"https://api.github.com/repos/munificent/wren/pulls/381","html_url":"https://github.com/munificent/wren/pull/381","diff_url":"https://github.com/munificent/wren/pull/381.diff","patch_url":"https://github.com/munificent/wren/pull/381.patch"},"body":"The ability to offset the search inside the string is critical for many string operations.\r\nA good example is a string split (or replace) method (implemented in wren, not in core). \r\nWithout the ability to consume the string without a copy, the alternative is to duplicate \r\nthe remaining part, generating both new ranges and new strings. This is bad for garbage, \r\nand on larger strings like data files can get prohibitively expensive.\r\n\r\nIn my case, parsing/splitting a dense 92KB file (19582 lines) with several thousand split calls, by line, and then by token per line, dropped from ~750ms down to 14ms running time alone (for newlines, for further parsing it was around 70ms on top which didn't change much as the lines being split weren't as long).\r\n\r\nI added some basic tests, and ran the benchmarks before and after (see below).\r\n\r\n**Notes**\r\nThere are some things that I think could be improved in the implemenation detail later.\r\n\r\nFor example, it might be nice (and consistent) to have startIndex allow negative values, which would behave like ranges do and use the end as a marker. I also tried to keep the code as similar to what it was at first to make sure the differences are clear.\r\n\r\nFeedback welcome!\r\n\r\nThings I wasn't sure of specifically:\r\n- The `..indexOf_with_startIndex` naming\r\n- Whether or not it should be a separate function, or handled inside existing `indexOf` with arg checks. If so, how to query for unspecified args? IS_NULL returned false for those...\r\n\r\n**benchmark** \r\n\r\n```\r\napi_call - wren                .......... 0.10s 0.0028 101.67% relative to baseline\r\napi_foreign_method - wren      .......... 0.45s 0.0097 100.73% relative to baseline\r\nbinary_trees - wren            .......... 0.36s 0.0060 100.34% relative to baseline\r\nbinary_trees_gc - wren         .......... 1.14s 0.0085 101.32% relative to baseline\r\ndelta_blue - wren              .......... 0.27s 0.0027 100.93% relative to baseline\r\nfib - wren                     .......... 0.32s 0.0047  97.67% relative to baseline\r\nfibers - wren                  .......... 0.06s 0.0022  99.09% relative to baseline\r\nfor - wren                     .......... 0.11s 0.0022 100.56% relative to baseline\r\nmethod_call - wren             .......... 0.22s 0.0043 104.13% relative to baseline\r\nmap_numeric - wren             .......... 0.37s 0.0034 100.27% relative to baseline\r\nmap_string - wren              .......... 0.15s 0.0016  99.58% relative to baseline\r\nstring_equals - wren           .......... 0.30s 0.0074 103.72% relative to baseline\r\n```"},"comment":{"url":"https://api.github.com/repos/munificent/wren/issues/comments/237479750","html_url":"https://github.com/munificent/wren/pull/381#issuecomment-237479750","issue_url":"https://api.github.com/repos/munificent/wren/issues/381","id":237479750,"user":{"login":"underscorediscovery","id":236374,"avatar_url":"https://avatars.githubusercontent.com/u/236374?v=3","gravatar_id":"","url":"https://api.github.com/users/underscorediscovery","html_url":"https://github.com/underscorediscovery","followers_url":"https://api.github.com/users/underscorediscovery/followers","following_url":"https://api.github.com/users/underscorediscovery/following{/other_user}","gists_url":"https://api.github.com/users/underscorediscovery/gists{/gist_id}","starred_url":"https://api.github.com/users/underscorediscovery/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/underscorediscovery/subscriptions","organizations_url":"https://api.github.com/users/underscorediscovery/orgs","repos_url":"https://api.github.com/users/underscorediscovery/repos","events_url":"https://api.github.com/users/underscorediscovery/events{/privacy}","received_events_url":"https://api.github.com/users/underscorediscovery/received_events","type":"User","site_admin":false},"created_at":"2016-08-04T07:53:32Z","updated_at":"2016-08-04T07:53:32Z","body":"Thanks for the notes, and happy to help!"}}
{"actor":{"display_login":"underscorediscovery"}}