{"action":"opened","number":1507,"pull_request":{"url":"https://api.github.com/repos/firebase/firebase-ios-sdk/pulls/1507","id":200195653,"node_id":"MDExOlB1bGxSZXF1ZXN0MjAwMTk1NjUz","html_url":"https://github.com/firebase/firebase-ios-sdk/pull/1507","diff_url":"https://github.com/firebase/firebase-ios-sdk/pull/1507.diff","patch_url":"https://github.com/firebase/firebase-ios-sdk/pull/1507.patch","issue_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/issues/1507","number":1507,"state":"open","locked":false,"title":"Eliminate unnecessary DocumentKey->FSTDocumentKey conversions","user":{"login":"var-const","id":8216808,"node_id":"MDQ6VXNlcjgyMTY4MDg=","avatar_url":"https://avatars1.githubusercontent.com/u/8216808?v=4","gravatar_id":"","url":"https://api.github.com/users/var-const","html_url":"https://github.com/var-const","followers_url":"https://api.github.com/users/var-const/followers","following_url":"https://api.github.com/users/var-const/following{/other_user}","gists_url":"https://api.github.com/users/var-const/gists{/gist_id}","starred_url":"https://api.github.com/users/var-const/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/var-const/subscriptions","organizations_url":"https://api.github.com/users/var-const/orgs","repos_url":"https://api.github.com/users/var-const/repos","events_url":"https://api.github.com/users/var-const/events{/privacy}","received_events_url":"https://api.github.com/users/var-const/received_events","type":"User","site_admin":false},"body":"This came up while optimizing batches with many mutations. Most of memory allocations and a good chunk of time was due to many unintentional conversions between the C++ `DocumentKey` and Objective-C `FSTDocumentKey`. There were two main issues:\r\n* the conversion from `DocumentKey` to `FSTDocumentKey` performed a full copy, instead of taking advantage of the internal optimization in `DocumentKey` that uses a `shared_ptr` to make copying cheap;\r\n* in a few places, instance variables of type `FSTDocumentKey` were replaced with `DocumentKey`, but the syntax for comparison wasn't updated. Because the conversion is implicit, the following code converts `DocumentKey`s to `FSTDocumentKey`s and then calls the method on them:\r\n```cpp\r\nDocumentKey foo;\r\nDocumentKey bar;\r\nreturn [foo isEqualToKey: bar];\r\n```\r\n\r\nThis is a follow-up to #1505. I found out that while #1505 improved things a lot, committing more than one batch with many mutations was still unreasonably slow. The profiler showed that most of the time was spent in creating `FSTDocumentKey`s. To benchmark, I used the newly-added performance test which commits a batch with 499 mutations, but created 50 such batches. I tested in release mode and just manually monitored memory usage and execution speed in XCode (on simulator). I got the following stats:\r\n* the original state: 50 batches of 499 mutations take 239 seconds to run, peak memory usage is 3.6 GB;\r\n* with #1505: 55 seconds, 1.8 GB;\r\n* with this PR: 24 seconds, 130 MB.\r\n\r\nFurther optimizations to `FSTLocalDocumentsView` seem not to be worth it. Even skipping access to LevelDB altogether inside `FSTLocalDocumentsView` only brings down total time to 19-20 seconds.","created_at":"2018-07-09T19:23:45Z","updated_at":"2018-07-09T19:23:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/pulls/1507/commits","review_comments_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/pulls/1507/comments","review_comment_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/pulls/comments{/number}","comments_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/issues/1507/comments","statuses_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/statuses/158877c410a5962d83cf842e70331239fbbb7b3e","head":{"label":"firebase:varconst/write-batch-opt-2","ref":"varconst/write-batch-opt-2","sha":"158877c410a5962d83cf842e70331239fbbb7b3e","user":{"login":"firebase","id":1335026,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEzMzUwMjY=","avatar_url":"https://avatars2.githubusercontent.com/u/1335026?v=4","gravatar_id":"","url":"https://api.github.com/users/firebase","html_url":"https://github.com/firebase","followers_url":"https://api.github.com/users/firebase/followers","following_url":"https://api.github.com/users/firebase/following{/other_user}","gists_url":"https://api.github.com/users/firebase/gists{/gist_id}","starred_url":"https://api.github.com/users/firebase/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/firebase/subscriptions","organizations_url":"https://api.github.com/users/firebase/orgs","repos_url":"https://api.github.com/users/firebase/repos","events_url":"https://api.github.com/users/firebase/events{/privacy}","received_events_url":"https://api.github.com/users/firebase/received_events","type":"Organization","site_admin":false},"repo":{"id":89033556,"node_id":"MDEwOlJlcG9zaXRvcnk4OTAzMzU1Ng==","name":"firebase-ios-sdk","full_name":"firebase/firebase-ios-sdk","owner":{"login":"firebase","id":1335026,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEzMzUwMjY=","avatar_url":"https://avatars2.githubusercontent.com/u/1335026?v=4","gravatar_id":"","url":"https://api.github.com/users/firebase","html_url":"https://github.com/firebase","followers_url":"https://api.github.com/users/firebase/followers","following_url":"https://api.github.com/users/firebase/following{/other_user}","gists_url":"https://api.github.com/users/firebase/gists{/gist_id}","starred_url":"https://api.github.com/users/firebase/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/firebase/subscriptions","organizations_url":"https://api.github.com/users/firebase/orgs","repos_url":"https://api.github.com/users/firebase/repos","events_url":"https://api.github.com/users/firebase/events{/privacy}","received_events_url":"https://api.github.com/users/firebase/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/firebase/firebase-ios-sdk","description":"Firebase iOS SDK","fork":false,"url":"https://api.github.com/repos/firebase/firebase-ios-sdk","forks_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/forks","keys_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/teams","hooks_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/hooks","issue_events_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/issues/events{/number}","events_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/events","assignees_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/assignees{/user}","branches_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/branches{/branch}","tags_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/tags","blobs_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/git/refs{/sha}","trees_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/statuses/{sha}","languages_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/languages","stargazers_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/stargazers","contributors_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/contributors","subscribers_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/subscribers","subscription_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/subscription","commits_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/commits{/sha}","git_commits_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/git/commits{/sha}","comments_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/comments{/number}","issue_comment_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/issues/comments{/number}","contents_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/contents/{+path}","compare_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/merges","archive_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/downloads","issues_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/issues{/number}","pulls_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/pulls{/number}","milestones_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/milestones{/number}","notifications_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/labels{/name}","releases_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/releases{/id}","deployments_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/deployments","created_at":"2017-04-22T00:26:50Z","updated_at":"2018-07-09T17:56:12Z","pushed_at":"2018-07-09T19:10:50Z","git_url":"git://github.com/firebase/firebase-ios-sdk.git","ssh_url":"git@github.com:firebase/firebase-ios-sdk.git","clone_url":"https://github.com/firebase/firebase-ios-sdk.git","svn_url":"https://github.com/firebase/firebase-ios-sdk","homepage":"https://firebase.google.com","size":88938,"stargazers_count":737,"watchers_count":737,"language":"Objective-C","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":147,"mirror_url":null,"archived":false,"open_issues_count":87,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":147,"open_issues":87,"watchers":737,"default_branch":"master"}},"base":{"label":"firebase:master","ref":"master","sha":"637e5aa468ab0c3b1faa3b7970ad3e91fb6c6f74","user":{"login":"firebase","id":1335026,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEzMzUwMjY=","avatar_url":"https://avatars2.githubusercontent.com/u/1335026?v=4","gravatar_id":"","url":"https://api.github.com/users/firebase","html_url":"https://github.com/firebase","followers_url":"https://api.github.com/users/firebase/followers","following_url":"https://api.github.com/users/firebase/following{/other_user}","gists_url":"https://api.github.com/users/firebase/gists{/gist_id}","starred_url":"https://api.github.com/users/firebase/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/firebase/subscriptions","organizations_url":"https://api.github.com/users/firebase/orgs","repos_url":"https://api.github.com/users/firebase/repos","events_url":"https://api.github.com/users/firebase/events{/privacy}","received_events_url":"https://api.github.com/users/firebase/received_events","type":"Organization","site_admin":false},"repo":{"id":89033556,"node_id":"MDEwOlJlcG9zaXRvcnk4OTAzMzU1Ng==","name":"firebase-ios-sdk","full_name":"firebase/firebase-ios-sdk","owner":{"login":"firebase","id":1335026,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEzMzUwMjY=","avatar_url":"https://avatars2.githubusercontent.com/u/1335026?v=4","gravatar_id":"","url":"https://api.github.com/users/firebase","html_url":"https://github.com/firebase","followers_url":"https://api.github.com/users/firebase/followers","following_url":"https://api.github.com/users/firebase/following{/other_user}","gists_url":"https://api.github.com/users/firebase/gists{/gist_id}","starred_url":"https://api.github.com/users/firebase/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/firebase/subscriptions","organizations_url":"https://api.github.com/users/firebase/orgs","repos_url":"https://api.github.com/users/firebase/repos","events_url":"https://api.github.com/users/firebase/events{/privacy}","received_events_url":"https://api.github.com/users/firebase/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/firebase/firebase-ios-sdk","description":"Firebase iOS SDK","fork":false,"url":"https://api.github.com/repos/firebase/firebase-ios-sdk","forks_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/forks","keys_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/teams","hooks_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/hooks","issue_events_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/issues/events{/number}","events_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/events","assignees_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/assignees{/user}","branches_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/branches{/branch}","tags_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/tags","blobs_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/git/refs{/sha}","trees_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/statuses/{sha}","languages_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/languages","stargazers_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/stargazers","contributors_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/contributors","subscribers_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/subscribers","subscription_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/subscription","commits_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/commits{/sha}","git_commits_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/git/commits{/sha}","comments_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/comments{/number}","issue_comment_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/issues/comments{/number}","contents_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/contents/{+path}","compare_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/merges","archive_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/downloads","issues_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/issues{/number}","pulls_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/pulls{/number}","milestones_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/milestones{/number}","notifications_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/labels{/name}","releases_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/releases{/id}","deployments_url":"https://api.github.com/repos/firebase/firebase-ios-sdk/deployments","created_at":"2017-04-22T00:26:50Z","updated_at":"2018-07-09T17:56:12Z","pushed_at":"2018-07-09T19:10:50Z","git_url":"git://github.com/firebase/firebase-ios-sdk.git","ssh_url":"git@github.com:firebase/firebase-ios-sdk.git","clone_url":"https://github.com/firebase/firebase-ios-sdk.git","svn_url":"https://github.com/firebase/firebase-ios-sdk","homepage":"https://firebase.google.com","size":88938,"stargazers_count":737,"watchers_count":737,"language":"Objective-C","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":147,"mirror_url":null,"archived":false,"open_issues_count":87,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":147,"open_issues":87,"watchers":737,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/firebase/firebase-ios-sdk/pulls/1507"},"html":{"href":"https://github.com/firebase/firebase-ios-sdk/pull/1507"},"issue":{"href":"https://api.github.com/repos/firebase/firebase-ios-sdk/issues/1507"},"comments":{"href":"https://api.github.com/repos/firebase/firebase-ios-sdk/issues/1507/comments"},"review_comments":{"href":"https://api.github.com/repos/firebase/firebase-ios-sdk/pulls/1507/comments"},"review_comment":{"href":"https://api.github.com/repos/firebase/firebase-ios-sdk/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/firebase/firebase-ios-sdk/pulls/1507/commits"},"statuses":{"href":"https://api.github.com/repos/firebase/firebase-ios-sdk/statuses/158877c410a5962d83cf842e70331239fbbb7b3e"}},"author_association":"COLLABORATOR","merged":false,"mergeable":null,"rebaseable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"maintainer_can_modify":false,"commits":2,"additions":92,"deletions":30,"changed_files":10}}
{"actor":{"display_login":"var-const"}}