{"action":"created","issue":{"url":"https://api.github.com/repos/eclipse/eclipse-collections/issues/116","repository_url":"https://api.github.com/repos/eclipse/eclipse-collections","labels_url":"https://api.github.com/repos/eclipse/eclipse-collections/issues/116/labels{/name}","comments_url":"https://api.github.com/repos/eclipse/eclipse-collections/issues/116/comments","events_url":"https://api.github.com/repos/eclipse/eclipse-collections/issues/116/events","html_url":"https://github.com/eclipse/eclipse-collections/issues/116","id":159146210,"number":116,"title":"improve speed of chunk() of List implementations","user":{"login":"jackhammer2k","id":10447953,"avatar_url":"https://avatars.githubusercontent.com/u/10447953?v=3","gravatar_id":"","url":"https://api.github.com/users/jackhammer2k","html_url":"https://github.com/jackhammer2k","followers_url":"https://api.github.com/users/jackhammer2k/followers","following_url":"https://api.github.com/users/jackhammer2k/following{/other_user}","gists_url":"https://api.github.com/users/jackhammer2k/gists{/gist_id}","starred_url":"https://api.github.com/users/jackhammer2k/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jackhammer2k/subscriptions","organizations_url":"https://api.github.com/users/jackhammer2k/orgs","repos_url":"https://api.github.com/users/jackhammer2k/repos","events_url":"https://api.github.com/users/jackhammer2k/events{/privacy}","received_events_url":"https://api.github.com/users/jackhammer2k/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-06-08T11:59:22Z","updated_at":"2016-06-13T07:31:39Z","closed_at":null,"body":"We've noticed that the chunk() implementation of FastList (actually AbstractMutableCollection) iterates over the whole list and creates a new list containing chunked lists. We're using Guavas Lists.partition() method (which uses sublists instead) on top of FastList to get performance speed up.\r\nClasses implementing List like FastList should implement chunk() by using sublists.\r\n\r\nHere our benchmark:\r\n\r\n```\r\npublic class FastListBenchmark {\r\n    @State(Scope.Thread)\r\n    public static class MyState {\r\n        FastList<Integer> list;\r\n\r\n        @Setup(Level.Trial)\r\n        public void doSetup() {\r\n            list = new FastList<>();\r\n            for (int i = 0; i < 10000000; i++) {\r\n                list.add(i);\r\n            }\r\n        }\r\n    }\r\n\r\n    @Benchmark\r\n    @BenchmarkMode(Mode.All)\r\n    public void parallelIterationViaChunk(MyState myState) throws ExecutionException, InterruptedException {\r\n        RichIterable<RichIterable<Integer>> partitionedValues = myState.list\r\n                .chunk(myState.list.size() / (Executor.NUMBEROFTHREADS * 8));\r\n        iterate(partitionedValues);\r\n    }\r\n\r\n    @Benchmark\r\n    @BenchmarkMode(Mode.All)\r\n    public void parallelIterationViaPartition(MyState myState) throws ExecutionException, InterruptedException {\r\n        List<List<Integer>> partitionedValues = Lists\r\n                .partition(myState.list, myState.list.size() / (Executor.NUMBEROFTHREADS * 8));\r\n        iterate(partitionedValues);\r\n    }\r\n\r\n    private void iterate(Iterable<? extends Iterable<?>> partitionedValues)\r\n            throws ExecutionException, InterruptedException {\r\n        Collection<Runnable> jobs = new ArrayList<>();\r\n        for (Iterable<?> values : partitionedValues) {\r\n            jobs.add(() -> {\r\n                for (Object value : values) {\r\n                    foobar();\r\n                }\r\n            });\r\n        }\r\n        new Executor().execute(jobs);\r\n    }\r\n}\r\n\r\npublic class Executor {\r\n\r\n    public static final int NUMBEROFTHREADS = Runtime.getRuntime().availableProcessors();\r\n\r\n    public final ExecutorService executor = Executors.newFixedThreadPool(NUMBEROFTHREADS);\r\n\r\n    public void execute(Collection<Runnable> jobs) throws ExecutionException, InterruptedException {\r\n        for (Runnable job : jobs) {\r\n            executor.execute(job);\r\n        }\r\n        executor.shutdown(); // !!! not shutdownNow\r\n        executor.awaitTermination(1, TimeUnit.HOURS);\r\n    }\r\n}\r\n```\r\n\r\n**Benchmark                                          Mode    Cnt   Score    Error  Units**\r\nFastListBenchmark.parallelIterationViaChunk       thrpt    200  13.286 ±  0.042  ops/s\r\nFastListBenchmark.parallelIterationViaPartition   thrpt    200  74.269 ±  0.445  ops/s\r\nFastListBenchmark.parallelIterationViaChunk        avgt    200   0.075 ±  0.001   s/op\r\nFastListBenchmark.parallelIterationViaPartition    avgt    200   0.013 ±  0.001   s/op\r\nFastListBenchmark.parallelIterationViaChunk      sample   2689   0.077 ±  0.001   s/op\r\nFastListBenchmark.parallelIterationViaPartition  sample  14114   0.014 ±  0.001   s/op\r\nFastListBenchmark.parallelIterationViaChunk          ss     10   1.668 ±  0.043   s/op\r\nFastListBenchmark.parallelIterationViaPartition      ss     10   1.472 ±  0.056   s/op\r\n"},"comment":{"url":"https://api.github.com/repos/eclipse/eclipse-collections/issues/comments/225507622","html_url":"https://github.com/eclipse/eclipse-collections/issues/116#issuecomment-225507622","issue_url":"https://api.github.com/repos/eclipse/eclipse-collections/issues/116","id":225507622,"user":{"login":"jackhammer2k","id":10447953,"avatar_url":"https://avatars.githubusercontent.com/u/10447953?v=3","gravatar_id":"","url":"https://api.github.com/users/jackhammer2k","html_url":"https://github.com/jackhammer2k","followers_url":"https://api.github.com/users/jackhammer2k/followers","following_url":"https://api.github.com/users/jackhammer2k/following{/other_user}","gists_url":"https://api.github.com/users/jackhammer2k/gists{/gist_id}","starred_url":"https://api.github.com/users/jackhammer2k/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jackhammer2k/subscriptions","organizations_url":"https://api.github.com/users/jackhammer2k/orgs","repos_url":"https://api.github.com/users/jackhammer2k/repos","events_url":"https://api.github.com/users/jackhammer2k/events{/privacy}","received_events_url":"https://api.github.com/users/jackhammer2k/received_events","type":"User","site_admin":false},"created_at":"2016-06-13T07:31:39Z","updated_at":"2016-06-13T07:31:39Z","body":"created pull request #118"}}
{"actor":{"display_login":"jackhammer2k"}}