{"action":"created","comment":{"url":"https://api.github.com/repos/realm/realm-java/pulls/comments/68205063","id":68205063,"diff_hunk":"@@ -784,6 +784,64 @@ private Scanner getFullStringScanner(InputStream in) {\n     }\n \n     /**\n+     * Bulk insert of a list of unmanaged RealmObjects, this is generally faster than {@link #copyToRealm(Iterable)} since it\n+     * doesn't return the inserted elements, and performs minimum allocations and checks.\n+     * <p>\n+     * Please note, this doesn't check if the object is already managed or not.\n+     * Copying an object will copy all field values. Any unset field in the object and child objects will be\n+     * set to their default value if not provided.\n+     *\n+     * @param objects RealmObjects to insert.\n+     */\n+    public void insert(Collection<? extends RealmModel> objects) {\n+        configuration.getSchemaMediator().insertToRealm(this, objects);\n+    }\n+\n+    /**\n+     * Insert of unmanaged RealmObject, this is generally faster than {@link #copyToRealm(RealmModel)} since it\n+     * doesn't return the inserted elements, and performs minimum allocations and checks.\n+     * <p>\n+     * Please note, this doesn't check if the object is already managed or not.\n+     * Copying an object will copy all field values. Any unset field in the object and child objects will be\n+     * set to their default value if not provided.\n+     *\n+     * @param object RealmObjects to insert.\n+     */\n+    public void insert(RealmModel object) {\n+        Map<RealmModel, Long> cache = new IdentityHashMap<RealmModel, Long>();\n+        configuration.getSchemaMediator().insertToRealm(this, object, cache);\n+    }\n+\n+    /**\n+     * Bulk insert or update of a list of unmanaged RealmObjects, this is generally faster than {@link #copyToRealmOrUpdate(Iterable)} since it","path":"realm/realm-library/src/main/java/io/realm/Realm.java","position":59,"original_position":59,"commit_id":"b14efe28fcfd5fcd8b51b6e8b6ceae36e3d7965f","original_commit_id":"b14efe28fcfd5fcd8b51b6e8b6ceae36e3d7965f","user":{"login":"cmelchior","id":406066,"avatar_url":"https://avatars.githubusercontent.com/u/406066?v=3","gravatar_id":"","url":"https://api.github.com/users/cmelchior","html_url":"https://github.com/cmelchior","followers_url":"https://api.github.com/users/cmelchior/followers","following_url":"https://api.github.com/users/cmelchior/following{/other_user}","gists_url":"https://api.github.com/users/cmelchior/gists{/gist_id}","starred_url":"https://api.github.com/users/cmelchior/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cmelchior/subscriptions","organizations_url":"https://api.github.com/users/cmelchior/orgs","repos_url":"https://api.github.com/users/cmelchior/repos","events_url":"https://api.github.com/users/cmelchior/events{/privacy}","received_events_url":"https://api.github.com/users/cmelchior/received_events","type":"User","site_admin":false},"body":"Bulk insert or update of a list -> Insert or update a list of unmanaged","created_at":"2016-06-23T09:42:56Z","updated_at":"2016-06-23T09:42:56Z","html_url":"https://github.com/realm/realm-java/pull/2999#discussion_r68205063","pull_request_url":"https://api.github.com/repos/realm/realm-java/pulls/2999","_links":{"self":{"href":"https://api.github.com/repos/realm/realm-java/pulls/comments/68205063"},"html":{"href":"https://github.com/realm/realm-java/pull/2999#discussion_r68205063"},"pull_request":{"href":"https://api.github.com/repos/realm/realm-java/pulls/2999"}}},"pull_request":{"url":"https://api.github.com/repos/realm/realm-java/pulls/2999","id":73837435,"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","issue_url":"https://api.github.com/repos/realm/realm-java/issues/2999","number":2999,"state":"open","locked":false,"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},"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","created_at":"2016-06-15T00:55:13Z","updated_at":"2016-06-23T09:42:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"dec726e39f1c33267aa70e090fb2338cbfa656ee","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},"milestone":null,"commits_url":"https://api.github.com/repos/realm/realm-java/pulls/2999/commits","review_comments_url":"https://api.github.com/repos/realm/realm-java/pulls/2999/comments","review_comment_url":"https://api.github.com/repos/realm/realm-java/pulls/comments{/number}","comments_url":"https://api.github.com/repos/realm/realm-java/issues/2999/comments","statuses_url":"https://api.github.com/repos/realm/realm-java/statuses/b14efe28fcfd5fcd8b51b6e8b6ceae36e3d7965f","head":{"label":"realm:nh/bulk_insert","ref":"nh/bulk_insert","sha":"b14efe28fcfd5fcd8b51b6e8b6ceae36e3d7965f","user":{"login":"realm","id":7575099,"avatar_url":"https://avatars.githubusercontent.com/u/7575099?v=3","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"repo":{"id":4084908,"name":"realm-java","full_name":"realm/realm-java","owner":{"login":"realm","id":7575099,"avatar_url":"https://avatars.githubusercontent.com/u/7575099?v=3","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/realm/realm-java","description":"Realm is a mobile database: a replacement for SQLite & ORMs","fork":false,"url":"https://api.github.com/repos/realm/realm-java","forks_url":"https://api.github.com/repos/realm/realm-java/forks","keys_url":"https://api.github.com/repos/realm/realm-java/keys{/key_id}","collaborators_url":"https://api.github.com/repos/realm/realm-java/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/realm/realm-java/teams","hooks_url":"https://api.github.com/repos/realm/realm-java/hooks","issue_events_url":"https://api.github.com/repos/realm/realm-java/issues/events{/number}","events_url":"https://api.github.com/repos/realm/realm-java/events","assignees_url":"https://api.github.com/repos/realm/realm-java/assignees{/user}","branches_url":"https://api.github.com/repos/realm/realm-java/branches{/branch}","tags_url":"https://api.github.com/repos/realm/realm-java/tags","blobs_url":"https://api.github.com/repos/realm/realm-java/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/realm/realm-java/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/realm/realm-java/git/refs{/sha}","trees_url":"https://api.github.com/repos/realm/realm-java/git/trees{/sha}","statuses_url":"https://api.github.com/repos/realm/realm-java/statuses/{sha}","languages_url":"https://api.github.com/repos/realm/realm-java/languages","stargazers_url":"https://api.github.com/repos/realm/realm-java/stargazers","contributors_url":"https://api.github.com/repos/realm/realm-java/contributors","subscribers_url":"https://api.github.com/repos/realm/realm-java/subscribers","subscription_url":"https://api.github.com/repos/realm/realm-java/subscription","commits_url":"https://api.github.com/repos/realm/realm-java/commits{/sha}","git_commits_url":"https://api.github.com/repos/realm/realm-java/git/commits{/sha}","comments_url":"https://api.github.com/repos/realm/realm-java/comments{/number}","issue_comment_url":"https://api.github.com/repos/realm/realm-java/issues/comments{/number}","contents_url":"https://api.github.com/repos/realm/realm-java/contents/{+path}","compare_url":"https://api.github.com/repos/realm/realm-java/compare/{base}...{head}","merges_url":"https://api.github.com/repos/realm/realm-java/merges","archive_url":"https://api.github.com/repos/realm/realm-java/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/realm/realm-java/downloads","issues_url":"https://api.github.com/repos/realm/realm-java/issues{/number}","pulls_url":"https://api.github.com/repos/realm/realm-java/pulls{/number}","milestones_url":"https://api.github.com/repos/realm/realm-java/milestones{/number}","notifications_url":"https://api.github.com/repos/realm/realm-java/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/realm/realm-java/labels{/name}","releases_url":"https://api.github.com/repos/realm/realm-java/releases{/id}","deployments_url":"https://api.github.com/repos/realm/realm-java/deployments","created_at":"2012-04-20T09:18:42Z","updated_at":"2016-06-23T08:53:51Z","pushed_at":"2016-06-23T09:40:27Z","git_url":"git://github.com/realm/realm-java.git","ssh_url":"git@github.com:realm/realm-java.git","clone_url":"https://github.com/realm/realm-java.git","svn_url":"https://github.com/realm/realm-java","homepage":"http://realm.io","size":62862,"stargazers_count":5318,"watchers_count":5318,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":719,"mirror_url":null,"open_issues_count":260,"forks":719,"open_issues":260,"watchers":5318,"default_branch":"master"}},"base":{"label":"realm:master","ref":"master","sha":"76c6178c01ff62c69d95543b219a4c23f5a23873","user":{"login":"realm","id":7575099,"avatar_url":"https://avatars.githubusercontent.com/u/7575099?v=3","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"repo":{"id":4084908,"name":"realm-java","full_name":"realm/realm-java","owner":{"login":"realm","id":7575099,"avatar_url":"https://avatars.githubusercontent.com/u/7575099?v=3","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/realm/realm-java","description":"Realm is a mobile database: a replacement for SQLite & ORMs","fork":false,"url":"https://api.github.com/repos/realm/realm-java","forks_url":"https://api.github.com/repos/realm/realm-java/forks","keys_url":"https://api.github.com/repos/realm/realm-java/keys{/key_id}","collaborators_url":"https://api.github.com/repos/realm/realm-java/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/realm/realm-java/teams","hooks_url":"https://api.github.com/repos/realm/realm-java/hooks","issue_events_url":"https://api.github.com/repos/realm/realm-java/issues/events{/number}","events_url":"https://api.github.com/repos/realm/realm-java/events","assignees_url":"https://api.github.com/repos/realm/realm-java/assignees{/user}","branches_url":"https://api.github.com/repos/realm/realm-java/branches{/branch}","tags_url":"https://api.github.com/repos/realm/realm-java/tags","blobs_url":"https://api.github.com/repos/realm/realm-java/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/realm/realm-java/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/realm/realm-java/git/refs{/sha}","trees_url":"https://api.github.com/repos/realm/realm-java/git/trees{/sha}","statuses_url":"https://api.github.com/repos/realm/realm-java/statuses/{sha}","languages_url":"https://api.github.com/repos/realm/realm-java/languages","stargazers_url":"https://api.github.com/repos/realm/realm-java/stargazers","contributors_url":"https://api.github.com/repos/realm/realm-java/contributors","subscribers_url":"https://api.github.com/repos/realm/realm-java/subscribers","subscription_url":"https://api.github.com/repos/realm/realm-java/subscription","commits_url":"https://api.github.com/repos/realm/realm-java/commits{/sha}","git_commits_url":"https://api.github.com/repos/realm/realm-java/git/commits{/sha}","comments_url":"https://api.github.com/repos/realm/realm-java/comments{/number}","issue_comment_url":"https://api.github.com/repos/realm/realm-java/issues/comments{/number}","contents_url":"https://api.github.com/repos/realm/realm-java/contents/{+path}","compare_url":"https://api.github.com/repos/realm/realm-java/compare/{base}...{head}","merges_url":"https://api.github.com/repos/realm/realm-java/merges","archive_url":"https://api.github.com/repos/realm/realm-java/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/realm/realm-java/downloads","issues_url":"https://api.github.com/repos/realm/realm-java/issues{/number}","pulls_url":"https://api.github.com/repos/realm/realm-java/pulls{/number}","milestones_url":"https://api.github.com/repos/realm/realm-java/milestones{/number}","notifications_url":"https://api.github.com/repos/realm/realm-java/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/realm/realm-java/labels{/name}","releases_url":"https://api.github.com/repos/realm/realm-java/releases{/id}","deployments_url":"https://api.github.com/repos/realm/realm-java/deployments","created_at":"2012-04-20T09:18:42Z","updated_at":"2016-06-23T08:53:51Z","pushed_at":"2016-06-23T09:40:27Z","git_url":"git://github.com/realm/realm-java.git","ssh_url":"git@github.com:realm/realm-java.git","clone_url":"https://github.com/realm/realm-java.git","svn_url":"https://github.com/realm/realm-java","homepage":"http://realm.io","size":62862,"stargazers_count":5318,"watchers_count":5318,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":719,"mirror_url":null,"open_issues_count":260,"forks":719,"open_issues":260,"watchers":5318,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/realm/realm-java/pulls/2999"},"html":{"href":"https://github.com/realm/realm-java/pull/2999"},"issue":{"href":"https://api.github.com/repos/realm/realm-java/issues/2999"},"comments":{"href":"https://api.github.com/repos/realm/realm-java/issues/2999/comments"},"review_comments":{"href":"https://api.github.com/repos/realm/realm-java/pulls/2999/comments"},"review_comment":{"href":"https://api.github.com/repos/realm/realm-java/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/realm/realm-java/pulls/2999/commits"},"statuses":{"href":"https://api.github.com/repos/realm/realm-java/statuses/b14efe28fcfd5fcd8b51b6e8b6ceae36e3d7965f"}}}}
{"actor":{"display_login":"cmelchior"}}