{"action":"created","issue":{"url":"https://api.github.com/repos/realm/realm-java/issues/2999","repository_url":"https://api.github.com/repos/realm/realm-java","labels_url":"https://api.github.com/repos/realm/realm-java/issues/2999/labels{/name}","comments_url":"https://api.github.com/repos/realm/realm-java/issues/2999/comments","events_url":"https://api.github.com/repos/realm/realm-java/issues/2999/events","html_url":"https://github.com/realm/realm-java/pull/2999","id":160317059,"number":2999,"title":"bulk inserts","user":{"login":"nhachicha","id":1793238,"avatar_url":"https://avatars.githubusercontent.com/u/1793238?v=3","gravatar_id":"","url":"https://api.github.com/users/nhachicha","html_url":"https://github.com/nhachicha","followers_url":"https://api.github.com/users/nhachicha/followers","following_url":"https://api.github.com/users/nhachicha/following{/other_user}","gists_url":"https://api.github.com/users/nhachicha/gists{/gist_id}","starred_url":"https://api.github.com/users/nhachicha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nhachicha/subscriptions","organizations_url":"https://api.github.com/users/nhachicha/orgs","repos_url":"https://api.github.com/users/nhachicha/repos","events_url":"https://api.github.com/users/nhachicha/events{/privacy}","received_events_url":"https://api.github.com/users/nhachicha/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/realm/realm-java/labels/S:Review","name":"S:Review","color":"ededed"},{"url":"https://api.github.com/repos/realm/realm-java/labels/T:Enhancement","name":"T:Enhancement","color":"bfe5bf"}],"state":"open","locked":false,"assignee":{"login":"nhachicha","id":1793238,"avatar_url":"https://avatars.githubusercontent.com/u/1793238?v=3","gravatar_id":"","url":"https://api.github.com/users/nhachicha","html_url":"https://github.com/nhachicha","followers_url":"https://api.github.com/users/nhachicha/followers","following_url":"https://api.github.com/users/nhachicha/following{/other_user}","gists_url":"https://api.github.com/users/nhachicha/gists{/gist_id}","starred_url":"https://api.github.com/users/nhachicha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nhachicha/subscriptions","organizations_url":"https://api.github.com/users/nhachicha/orgs","repos_url":"https://api.github.com/users/nhachicha/repos","events_url":"https://api.github.com/users/nhachicha/events{/privacy}","received_events_url":"https://api.github.com/users/nhachicha/received_events","type":"User","site_admin":false},"assignees":[{"login":"nhachicha","id":1793238,"avatar_url":"https://avatars.githubusercontent.com/u/1793238?v=3","gravatar_id":"","url":"https://api.github.com/users/nhachicha","html_url":"https://github.com/nhachicha","followers_url":"https://api.github.com/users/nhachicha/followers","following_url":"https://api.github.com/users/nhachicha/following{/other_user}","gists_url":"https://api.github.com/users/nhachicha/gists{/gist_id}","starred_url":"https://api.github.com/users/nhachicha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nhachicha/subscriptions","organizations_url":"https://api.github.com/users/nhachicha/orgs","repos_url":"https://api.github.com/users/nhachicha/repos","events_url":"https://api.github.com/users/nhachicha/events{/privacy}","received_events_url":"https://api.github.com/users/nhachicha/received_events","type":"User","site_admin":false}],"milestone":null,"comments":31,"created_at":"2016-06-15T00:55:13Z","updated_at":"2016-06-28T00:51:50Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/realm/realm-java/pulls/2999","html_url":"https://github.com/realm/realm-java/pull/2999","diff_url":"https://github.com/realm/realm-java/pull/2999.diff","patch_url":"https://github.com/realm/realm-java/pull/2999.patch"},"body":"Fixes https://github.com/realm/realm-java/issues/1684 \r\n\r\n# Benchmarks with 100_000 objects\r\n## Before (using `copyToRealm`)\r\n![benchmark_batchwrite](https://cloud.githubusercontent.com/assets/1793238/16064422/fdd88640-3298-11e6-9601-b9bdfbaabab2.png)\r\n\r\n\r\n## Using Bulk Inserts   \r\n![benchmark_batchwrite](https://cloud.githubusercontent.com/assets/1793238/16064440/2754c560-3299-11e6-8439-d64f6779eb44.png)\r\n\r\n# Cap \r\n\r\nThe new API accepts a list of `Collection` instead of a list of `Iterator` because we need to know the size of the collection, in order to optimise the `Map` that acts as a cache for the previously inserted objects.\r\nhere is an Android _traceview_ dump that stress the importance of initialising the `IdentityMap` to avoid the expensive `rehash` invocation for each `put` operation.\r\n\r\n## Without initialising the Map\r\n<img width=\"780\" src=\"https://cloud.githubusercontent.com/assets/1793238/16064630/cbf7d12e-329a-11e6-844f-1e95a2d9eeb5.png\">\r\nwe spend 35% of the overall time in the `put` operation \r\n<img width=\"693\" src=\"https://cloud.githubusercontent.com/assets/1793238/16064676/39c1bcf6-329b-11e6-915a-986eaeaaf0de.png\">\r\nthe `rehash` could be avoided if we initialise the Map with the appropriate size\r\n\r\n## Initialising the Map with the size of the Collection\r\n<img width=\"628\" alt=\"after_rehash_opts\" src=\"https://cloud.githubusercontent.com/assets/1793238/16064663/19aa16de-329b-11e6-9341-ac05cec7d0f1.png\">\r\n\r\nAlthough we reduced the overall time spent in the Map, we can't reach the performance of lowlevel Realm, because the lowlevel Realm doesn't need the `Map` to cache objects.\r\n"},"comment":{"url":"https://api.github.com/repos/realm/realm-java/issues/comments/228918781","html_url":"https://github.com/realm/realm-java/pull/2999#issuecomment-228918781","issue_url":"https://api.github.com/repos/realm/realm-java/issues/2999","id":228918781,"user":{"login":"nhachicha","id":1793238,"avatar_url":"https://avatars.githubusercontent.com/u/1793238?v=3","gravatar_id":"","url":"https://api.github.com/users/nhachicha","html_url":"https://github.com/nhachicha","followers_url":"https://api.github.com/users/nhachicha/followers","following_url":"https://api.github.com/users/nhachicha/following{/other_user}","gists_url":"https://api.github.com/users/nhachicha/gists{/gist_id}","starred_url":"https://api.github.com/users/nhachicha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nhachicha/subscriptions","organizations_url":"https://api.github.com/users/nhachicha/orgs","repos_url":"https://api.github.com/users/nhachicha/repos","events_url":"https://api.github.com/users/nhachicha/events{/privacy}","received_events_url":"https://api.github.com/users/nhachicha/received_events","type":"User","site_admin":false},"created_at":"2016-06-28T00:51:50Z","updated_at":"2016-06-28T00:51:50Z","body":"@realm/java "}}
{"actor":{"display_login":"nhachicha"}}