{"action":"created","issue":{"url":"https://api.github.com/repos/ramda/ramda/issues/1704","repository_url":"https://api.github.com/repos/ramda/ramda","labels_url":"https://api.github.com/repos/ramda/ramda/issues/1704/labels{/name}","comments_url":"https://api.github.com/repos/ramda/ramda/issues/1704/comments","events_url":"https://api.github.com/repos/ramda/ramda/issues/1704/events","html_url":"https://github.com/ramda/ramda/pull/1704","id":145128193,"number":1704,"title":"Optimize groupBy to use mutation in reducer","user":{"login":"ThomWright","id":1884486,"avatar_url":"https://avatars.githubusercontent.com/u/1884486?v=3","gravatar_id":"","url":"https://api.github.com/users/ThomWright","html_url":"https://github.com/ThomWright","followers_url":"https://api.github.com/users/ThomWright/followers","following_url":"https://api.github.com/users/ThomWright/following{/other_user}","gists_url":"https://api.github.com/users/ThomWright/gists{/gist_id}","starred_url":"https://api.github.com/users/ThomWright/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ThomWright/subscriptions","organizations_url":"https://api.github.com/users/ThomWright/orgs","repos_url":"https://api.github.com/users/ThomWright/repos","events_url":"https://api.github.com/users/ThomWright/events{/privacy}","received_events_url":"https://api.github.com/users/ThomWright/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2016-04-01T09:06:45Z","updated_at":"2016-04-02T11:48:35Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ramda/ramda/pulls/1704","html_url":"https://github.com/ramda/ramda/pull/1704","diff_url":"https://github.com/ramda/ramda/pull/1704.diff","patch_url":"https://github.com/ramda/ramda/pull/1704.patch"},"body":"Using `R.groupBy` on large arrays can get pretty slow.\r\n\r\nSimply using `arr.push()` instead of `R.append` improves performance significantly. Since the accumulator in the reducer is internal, this mutation shouldn't be a problem.\r\n\r\nSee [this perf test](http://jsperf.com/ramda-groupby-slow-for-large-arrays/2)\r\n\r\nAll credit to @davidgtonge\r\n\r\nAlso, I noticed `_xgroupBy.js`. Should this be updated too as part of this PR? I couldn't immediately see if it was safe to mutate instead of using `append` in that case."},"comment":{"url":"https://api.github.com/repos/ramda/ramda/issues/comments/204700070","html_url":"https://github.com/ramda/ramda/pull/1704#issuecomment-204700070","issue_url":"https://api.github.com/repos/ramda/ramda/issues/1704","id":204700070,"user":{"login":"davidgtonge","id":919587,"avatar_url":"https://avatars.githubusercontent.com/u/919587?v=3","gravatar_id":"","url":"https://api.github.com/users/davidgtonge","html_url":"https://github.com/davidgtonge","followers_url":"https://api.github.com/users/davidgtonge/followers","following_url":"https://api.github.com/users/davidgtonge/following{/other_user}","gists_url":"https://api.github.com/users/davidgtonge/gists{/gist_id}","starred_url":"https://api.github.com/users/davidgtonge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidgtonge/subscriptions","organizations_url":"https://api.github.com/users/davidgtonge/orgs","repos_url":"https://api.github.com/users/davidgtonge/repos","events_url":"https://api.github.com/users/davidgtonge/events{/privacy}","received_events_url":"https://api.github.com/users/davidgtonge/received_events","type":"User","site_admin":false},"created_at":"2016-04-02T11:48:35Z","updated_at":"2016-04-02T11:48:35Z","body":"Or - another option that doesn't require a change to reduceBy: http://goo.gl/F1F3zL\r\nThe valueFn becomes: \r\n```javascript\r\n(a, c) => {\r\n    (a.length) ? a.push(c) : a = [c]\r\n    return a;\r\n}\r\n```\r\n\r\n"}}