{"action":"created","comment":{"url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/pulls/comments/62448632","id":62448632,"diff_hunk":"@@ -10,37 +10,43 @@\n #import \"FBClassStrongLayout.h\"\n \n #import <math.h>\n+#import <memory>\n #import <objc/runtime.h>\n+#import <vector>\n \n #import <UIKit/UIKit.h>\n \n #import \"FBIvarReference.h\"\n #import \"FBObjectInStructReference.h\"\n #import \"FBStructEncodingParser.h\"\n+#import \"Struct.h\"\n+#import \"Type.h\"\n \n /**\n  If we stumble upon a struct, we need to go through it and check if it doesn't retain some objects.\n  */\n-static NSArray *FBGetReferencesForObjectsInStructEncoding(FBIvarReference *ivar, NSString *encoding) {\n+static NSArray *FBGetReferencesForObjectsInStructEncoding(FBIvarReference *ivar, std::string encoding) {\n   NSMutableArray<FBObjectInStructReference *> *references = [NSMutableArray new];\n \n-  FBParsedStruct *parsedStruct = FBParseStructEncodingWithName(encoding,\n-                                                         ivar.name);\n-  NSArray<FBParsedType *> *types = [parsedStruct flattenTypes];\n-\n+  std::string ivarName = std::string([ivar.name cStringUsingEncoding:NSUTF8StringEncoding]);\n+  FB::RetainCycleDetector::Parser::Struct parsedStruct =\n+  FB::RetainCycleDetector::Parser::parseStructEncodingWithName(encoding, ivarName);\n+  \n+  std::vector<std::shared_ptr<FB::RetainCycleDetector::Parser::Type>> types = parsedStruct.flattenTypes();\n+  \n   ptrdiff_t offset = ivar.offset;\n-\n-  for (FBParsedType *typeEncoding in types) {\n+  \n+  for (auto &type: types) {","path":"FBRetainCycleDetector/Layout/Classes/FBClassStrongLayout.mm","position":37,"original_position":37,"commit_id":"ac7daddc2a110a52676e73f9dd909600ead21ece","original_commit_id":"ac7daddc2a110a52676e73f9dd909600ead21ece","user":{"login":"kastiglione","id":43429,"avatar_url":"https://avatars.githubusercontent.com/u/43429?v=3","gravatar_id":"","url":"https://api.github.com/users/kastiglione","html_url":"https://github.com/kastiglione","followers_url":"https://api.github.com/users/kastiglione/followers","following_url":"https://api.github.com/users/kastiglione/following{/other_user}","gists_url":"https://api.github.com/users/kastiglione/gists{/gist_id}","starred_url":"https://api.github.com/users/kastiglione/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kastiglione/subscriptions","organizations_url":"https://api.github.com/users/kastiglione/orgs","repos_url":"https://api.github.com/users/kastiglione/repos","events_url":"https://api.github.com/users/kastiglione/events{/privacy}","received_events_url":"https://api.github.com/users/kastiglione/received_events","type":"User","site_admin":false},"body":"`const` to avoid making a copy of each string in `types`.","created_at":"2016-05-09T04:04:31Z","updated_at":"2016-05-09T04:04:31Z","html_url":"https://github.com/facebook/FBRetainCycleDetector/pull/9#discussion_r62448632","pull_request_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/pulls/9","_links":{"self":{"href":"https://api.github.com/repos/facebook/FBRetainCycleDetector/pulls/comments/62448632"},"html":{"href":"https://github.com/facebook/FBRetainCycleDetector/pull/9#discussion_r62448632"},"pull_request":{"href":"https://api.github.com/repos/facebook/FBRetainCycleDetector/pulls/9"}}},"pull_request":{"url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/pulls/9","id":69291585,"html_url":"https://github.com/facebook/FBRetainCycleDetector/pull/9","diff_url":"https://github.com/facebook/FBRetainCycleDetector/pull/9.diff","patch_url":"https://github.com/facebook/FBRetainCycleDetector/pull/9.patch","issue_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/issues/9","number":9,"state":"open","locked":false,"title":"Convert struct parsing to C++","user":{"login":"Gricha","id":875316,"avatar_url":"https://avatars.githubusercontent.com/u/875316?v=3","gravatar_id":"","url":"https://api.github.com/users/Gricha","html_url":"https://github.com/Gricha","followers_url":"https://api.github.com/users/Gricha/followers","following_url":"https://api.github.com/users/Gricha/following{/other_user}","gists_url":"https://api.github.com/users/Gricha/gists{/gist_id}","starred_url":"https://api.github.com/users/Gricha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gricha/subscriptions","organizations_url":"https://api.github.com/users/Gricha/orgs","repos_url":"https://api.github.com/users/Gricha/repos","events_url":"https://api.github.com/users/Gricha/events{/privacy}","received_events_url":"https://api.github.com/users/Gricha/received_events","type":"User","site_admin":false},"body":"This should be an improvement of parsing structs, C++ seems to be a little bit faster.\r\n\r\nI did a very back-of-the-envelope benchmarking and it looks good:\r\n\r\nWhen I had `FBAllocationTracker` and tried to parse same struct 100000 in a row, here are the results:\r\n\r\n```\r\nObj-C \r\n9.471428\r\n7.526253\r\n7.682342\r\n7.581723\r\n7.583891\r\n\r\nC++ implementation \r\n\r\n6.026485\r\n6.107784\r\n6.053525\r\n6.457405\r\n6.103512\r\n```\r\n\r\nNow in second step I enabled `FBAllocationTracker`, I have seen some bigger differences. I started constant allocation/deallocation on five queues simultaneously to give it a harder touch (might be a bit excessive, but outlined the result):\r\n\r\n```\r\nObj-C\r\n19.443240\r\n17.968314\r\n16.773120\r\n18.898159\r\n19.623163\r\n\r\nC++\r\n12.000455\r\n11.576286\r\n11.323406\r\n11.606184\r\n12.907327\r\n```\r\n\r\nThis result is more or less expected, because well, we are grabbing a lock in `alloc`, but it also shows that we still create a lot of objects in Retain cycle detector, which will need improving.","created_at":"2016-05-09T03:26:54Z","updated_at":"2016-05-09T04:04:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f35464cf8681a5fb75fe9df742383ce336609365","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/pulls/9/commits","review_comments_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/pulls/9/comments","review_comment_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/pulls/comments{/number}","comments_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/issues/9/comments","statuses_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/statuses/ac7daddc2a110a52676e73f9dd909600ead21ece","head":{"label":"facebook:optimize-struct-parsing","ref":"optimize-struct-parsing","sha":"ac7daddc2a110a52676e73f9dd909600ead21ece","user":{"login":"facebook","id":69631,"avatar_url":"https://avatars.githubusercontent.com/u/69631?v=3","gravatar_id":"","url":"https://api.github.com/users/facebook","html_url":"https://github.com/facebook","followers_url":"https://api.github.com/users/facebook/followers","following_url":"https://api.github.com/users/facebook/following{/other_user}","gists_url":"https://api.github.com/users/facebook/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook/subscriptions","organizations_url":"https://api.github.com/users/facebook/orgs","repos_url":"https://api.github.com/users/facebook/repos","events_url":"https://api.github.com/users/facebook/events{/privacy}","received_events_url":"https://api.github.com/users/facebook/received_events","type":"Organization","site_admin":false},"repo":{"id":55717457,"name":"FBRetainCycleDetector","full_name":"facebook/FBRetainCycleDetector","owner":{"login":"facebook","id":69631,"avatar_url":"https://avatars.githubusercontent.com/u/69631?v=3","gravatar_id":"","url":"https://api.github.com/users/facebook","html_url":"https://github.com/facebook","followers_url":"https://api.github.com/users/facebook/followers","following_url":"https://api.github.com/users/facebook/following{/other_user}","gists_url":"https://api.github.com/users/facebook/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook/subscriptions","organizations_url":"https://api.github.com/users/facebook/orgs","repos_url":"https://api.github.com/users/facebook/repos","events_url":"https://api.github.com/users/facebook/events{/privacy}","received_events_url":"https://api.github.com/users/facebook/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/facebook/FBRetainCycleDetector","description":"iOS library to help detecting retain cycles in runtime.","fork":false,"url":"https://api.github.com/repos/facebook/FBRetainCycleDetector","forks_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/forks","keys_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/keys{/key_id}","collaborators_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/teams","hooks_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/hooks","issue_events_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/issues/events{/number}","events_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/events","assignees_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/assignees{/user}","branches_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/branches{/branch}","tags_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/tags","blobs_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/git/refs{/sha}","trees_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/git/trees{/sha}","statuses_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/statuses/{sha}","languages_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/languages","stargazers_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/stargazers","contributors_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/contributors","subscribers_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/subscribers","subscription_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/subscription","commits_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/commits{/sha}","git_commits_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/git/commits{/sha}","comments_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/comments{/number}","issue_comment_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/issues/comments{/number}","contents_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/contents/{+path}","compare_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/compare/{base}...{head}","merges_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/merges","archive_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/downloads","issues_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/issues{/number}","pulls_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/pulls{/number}","milestones_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/milestones{/number}","notifications_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/labels{/name}","releases_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/releases{/id}","deployments_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/deployments","created_at":"2016-04-07T18:17:16Z","updated_at":"2016-05-09T03:12:18Z","pushed_at":"2016-05-09T03:26:54Z","git_url":"git://github.com/facebook/FBRetainCycleDetector.git","ssh_url":"git@github.com:facebook/FBRetainCycleDetector.git","clone_url":"https://github.com/facebook/FBRetainCycleDetector.git","svn_url":"https://github.com/facebook/FBRetainCycleDetector","homepage":null,"size":2978,"stargazers_count":1313,"watchers_count":1313,"language":"Objective-C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":74,"mirror_url":null,"open_issues_count":3,"forks":74,"open_issues":3,"watchers":1313,"default_branch":"master"}},"base":{"label":"facebook:master","ref":"master","sha":"d1a53156039740b6a0ce279f0c3eadf3bd99b77c","user":{"login":"facebook","id":69631,"avatar_url":"https://avatars.githubusercontent.com/u/69631?v=3","gravatar_id":"","url":"https://api.github.com/users/facebook","html_url":"https://github.com/facebook","followers_url":"https://api.github.com/users/facebook/followers","following_url":"https://api.github.com/users/facebook/following{/other_user}","gists_url":"https://api.github.com/users/facebook/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook/subscriptions","organizations_url":"https://api.github.com/users/facebook/orgs","repos_url":"https://api.github.com/users/facebook/repos","events_url":"https://api.github.com/users/facebook/events{/privacy}","received_events_url":"https://api.github.com/users/facebook/received_events","type":"Organization","site_admin":false},"repo":{"id":55717457,"name":"FBRetainCycleDetector","full_name":"facebook/FBRetainCycleDetector","owner":{"login":"facebook","id":69631,"avatar_url":"https://avatars.githubusercontent.com/u/69631?v=3","gravatar_id":"","url":"https://api.github.com/users/facebook","html_url":"https://github.com/facebook","followers_url":"https://api.github.com/users/facebook/followers","following_url":"https://api.github.com/users/facebook/following{/other_user}","gists_url":"https://api.github.com/users/facebook/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook/subscriptions","organizations_url":"https://api.github.com/users/facebook/orgs","repos_url":"https://api.github.com/users/facebook/repos","events_url":"https://api.github.com/users/facebook/events{/privacy}","received_events_url":"https://api.github.com/users/facebook/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/facebook/FBRetainCycleDetector","description":"iOS library to help detecting retain cycles in runtime.","fork":false,"url":"https://api.github.com/repos/facebook/FBRetainCycleDetector","forks_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/forks","keys_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/keys{/key_id}","collaborators_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/teams","hooks_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/hooks","issue_events_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/issues/events{/number}","events_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/events","assignees_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/assignees{/user}","branches_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/branches{/branch}","tags_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/tags","blobs_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/git/refs{/sha}","trees_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/git/trees{/sha}","statuses_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/statuses/{sha}","languages_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/languages","stargazers_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/stargazers","contributors_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/contributors","subscribers_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/subscribers","subscription_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/subscription","commits_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/commits{/sha}","git_commits_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/git/commits{/sha}","comments_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/comments{/number}","issue_comment_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/issues/comments{/number}","contents_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/contents/{+path}","compare_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/compare/{base}...{head}","merges_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/merges","archive_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/downloads","issues_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/issues{/number}","pulls_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/pulls{/number}","milestones_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/milestones{/number}","notifications_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/labels{/name}","releases_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/releases{/id}","deployments_url":"https://api.github.com/repos/facebook/FBRetainCycleDetector/deployments","created_at":"2016-04-07T18:17:16Z","updated_at":"2016-05-09T03:12:18Z","pushed_at":"2016-05-09T03:26:54Z","git_url":"git://github.com/facebook/FBRetainCycleDetector.git","ssh_url":"git@github.com:facebook/FBRetainCycleDetector.git","clone_url":"https://github.com/facebook/FBRetainCycleDetector.git","svn_url":"https://github.com/facebook/FBRetainCycleDetector","homepage":null,"size":2978,"stargazers_count":1313,"watchers_count":1313,"language":"Objective-C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":74,"mirror_url":null,"open_issues_count":3,"forks":74,"open_issues":3,"watchers":1313,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/facebook/FBRetainCycleDetector/pulls/9"},"html":{"href":"https://github.com/facebook/FBRetainCycleDetector/pull/9"},"issue":{"href":"https://api.github.com/repos/facebook/FBRetainCycleDetector/issues/9"},"comments":{"href":"https://api.github.com/repos/facebook/FBRetainCycleDetector/issues/9/comments"},"review_comments":{"href":"https://api.github.com/repos/facebook/FBRetainCycleDetector/pulls/9/comments"},"review_comment":{"href":"https://api.github.com/repos/facebook/FBRetainCycleDetector/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/facebook/FBRetainCycleDetector/pulls/9/commits"},"statuses":{"href":"https://api.github.com/repos/facebook/FBRetainCycleDetector/statuses/ac7daddc2a110a52676e73f9dd909600ead21ece"}}}}