Title: Poor groupBy performance · Issue #288 · functionaljava/functionaljava · GitHub
Open Graph Title: Poor groupBy performance · Issue #288 · functionaljava/functionaljava
X Title: Poor groupBy performance · Issue #288 · functionaljava/functionaljava
Description: Running this code: import fj.data.List; import fj.data.TreeMap; public class GroupByPerf { public static void main(String[] args) { System.out.println("warmup"); for (int i = 0; i < 10; i++) { testIt(5000); } System.out.println("real run...
Open Graph Description: Running this code: import fj.data.List; import fj.data.TreeMap; public class GroupByPerf { public static void main(String[] args) { System.out.println("warmup"); for (int i = 0; i < 10; i++) { test...
X Description: Running this code: import fj.data.List; import fj.data.TreeMap; public class GroupByPerf { public static void main(String[] args) { System.out.println("warmup"); for (int i = 0; i < 10...
Opengraph URL: https://github.com/functionaljava/functionaljava/issues/288
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Poor groupBy performance","articleBody":"Running this code:\n\n``` java\nimport fj.data.List;\nimport fj.data.TreeMap;\n\npublic class GroupByPerf\n{\n public static void main(String[] args)\n {\n System.out.println(\"warmup\");\n for (int i = 0; i \u003c 10; i++)\n {\n testIt(5000);\n\n }\n\n System.out.println(\"real run\");\n for (int i = 0; i \u003c 100000; i++)\n {\n testIt(50000);\n\n }\n }\n\n public static void testIt(int size)\n {\n List\u003cShrubbery> sh = List.range(0, size).map(x -> new Shrubbery(x%20, String.valueOf(x)));\n long now = System.currentTimeMillis();\n TreeMap\u003cLong, List\u003cShrubbery>> grouped = sh.groupBy(x -> x.id);\n System.out.println(\"duration \" + (System.currentTimeMillis()-now));\n }\n\n public static class Shrubbery\n {\n public final long id;\n public final String name;\n\n public Shrubbery(long id, String name)\n {\n this.id = id;\n this.name = name;\n }\n }\n```\n\n, yields ~350 millisecond run time for each iteration post the warmup phase, on my machine.\n\nI did a flight recording with jmc, a large portion of the time is spent rebalancing the underlying set, or otherwise in the set.\n\nI took a shot at a naive hashmap implementation, of course the semantic of the method is changed, but they are still grouped:\n\n``` java\nprivate static \u003cA, B> HashMap\u003cA, List\u003cB>> groupBy(List\u003cB> list, F\u003cB,A> keyF)\n {\n HashMap\u003cA, List.Buffer\u003cB>> res = HashMap.hashMap();\n list.foreachDoEffect(x-> {\n A key = keyF.f(x);\n Option\u003cList.Buffer\u003cB>> entry = res.get(key);\n if(entry.isSome())\n {\n entry.some().snoc(x);\n }\n else\n {\n res.set(key, List.Buffer.\u003cB>empty().snoc(x));\n }\n });\n\n return res.map(x->x, x->x.toList());\n }\n```\n\nThe performance of the above code is roughly on par with javautil Stream. (1-2 millis per run)\n\nDo you think should be at least a variant of the groupBy method which does not use a red-black tree? I am sure there are good reasons the signature is as it is, but also I think 300ms for 50000 elements is not something one will use in production.\n","author":{"url":"https://github.com/dimitarg","@type":"Person","name":"dimitarg"},"datePublished":"2016-07-18T12:06:28Z","url":"https://github.com/functionaljava/functionaljava/issues/288"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:ae33ff53-b0a3-7b78-fed8-ce435379ef03 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E678:352ABC:1878C9:22515F:6AFBDF1E |
| html-safe-nonce | bbfa7b492715239d4480df0b3eb87f88536afec3ea34fab9ce6e8729d1fd038e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNjc4OjM1MkFCQzoxODc4Qzk6MjI1MTVGOjZBRkJERjFFIiwidmlzaXRvcl9pZCI6IjI0NzkyMzQ3MTkxMDM1NzM3OTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d5933d4a0969df2225a863dc000f2d51a1a8860dc3d8d8c085c59da1bd19e60e |
| hovercard-subject-tag | issue:166078740 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/functionaljava/functionaljava/288/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c9e0f84155d5807ece616c5a77e4776eb976399478d64800f847e711d31e035e/functionaljava/functionaljava/issues/288 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c9e0f84155d5807ece616c5a77e4776eb976399478d64800f847e711d31e035e/functionaljava/functionaljava/issues/288 |
| og:image:alt | Running this code: import fj.data.List; import fj.data.TreeMap; public class GroupByPerf { public static void main(String[] args) { System.out.println("warmup"); for (int i = 0; i < 10; i++) { test... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dimitarg |
| hostname | github.com |
| expected-hostname | github.com |
| None | 744d4381b1c4dbd6d8736c7d7e5bbe7dc11217584e457a3555020c631764e8ec |
| turbo-cache-control | no-preview |
| go-import | github.com/functionaljava/functionaljava git https://github.com/functionaljava/functionaljava.git |
| octolytics-dimension-user_id | 458836 |
| octolytics-dimension-user_login | functionaljava |
| octolytics-dimension-repository_id | 1033614 |
| octolytics-dimension-repository_nwo | functionaljava/functionaljava |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1033614 |
| octolytics-dimension-repository_network_root_nwo | functionaljava/functionaljava |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | df859c48a4c8b4c0009c19bb4e82101aacb4b998 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width