{"action":"created","issue":{"url":"https://api.github.com/repos/realm/realm-cocoa/issues/3235","repository_url":"https://api.github.com/repos/realm/realm-cocoa","labels_url":"https://api.github.com/repos/realm/realm-cocoa/issues/3235/labels{/name}","comments_url":"https://api.github.com/repos/realm/realm-cocoa/issues/3235/comments","events_url":"https://api.github.com/repos/realm/realm-cocoa/issues/3235/events","html_url":"https://github.com/realm/realm-cocoa/pull/3235","id":134434405,"number":3235,"title":"Improve shared schema initialization performance","user":{"login":"bdash","id":54825,"avatar_url":"https://avatars.githubusercontent.com/u/54825?v=3","gravatar_id":"","url":"https://api.github.com/users/bdash","html_url":"https://github.com/bdash","followers_url":"https://api.github.com/users/bdash/followers","following_url":"https://api.github.com/users/bdash/following{/other_user}","gists_url":"https://api.github.com/users/bdash/gists{/gist_id}","starred_url":"https://api.github.com/users/bdash/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bdash/subscriptions","organizations_url":"https://api.github.com/users/bdash/orgs","repos_url":"https://api.github.com/users/bdash/repos","events_url":"https://api.github.com/users/bdash/events{/privacy}","received_events_url":"https://api.github.com/users/bdash/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/realm/realm-cocoa/labels/T:Enhancement","name":"T:Enhancement","color":"bfe5bf"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2016-02-17T23:35:47Z","updated_at":"2016-03-02T08:58:56Z","closed_at":"2016-02-23T19:27:43Z","pull_request":{"url":"https://api.github.com/repos/realm/realm-cocoa/pulls/3235","html_url":"https://github.com/realm/realm-cocoa/pull/3235","diff_url":"https://github.com/realm/realm-cocoa/pull/3235.diff","patch_url":"https://github.com/realm/realm-cocoa/pull/3235.patch"},"body":"On iOS 9.2, the time spent below `+[RLMSchema sharedSchema]` on the first call is dominated by the time that the Objective-C runtime spends flushing method caches as a result of calls to `class_addMethod` and `class_replaceMethod`. By eliminating several of these calls per accessor class we can take a significant chunk out of the cost of schema initialization. We do this by:\r\n\r\n* No longer overriding `+shouldIncludeInDefaultSchema:` on generated accessor classes. It's no longer necessary as marking the class as generated has the same effect of excluding the class from the default schema.\r\n* No longer overriding `+className` on accessor classes. `+[RLMObjectBase className]` now uses a map from `Class` to class name as an optimization rather than per-class overrides of the method. This is around 50% slower per invocation of `+className` than the previous approach, but this overhead should be dominated by any work performed by the caller.\r\n\r\nOn a user-supplied application this sequence of changes reduces the time spent below `+[RLMSchema sharedSchema]` during launch by 2/3 (on an iPad Air running iOS 9.2.1).\r\n\r\niOS 9.3 appears to have optimized the method cache flushing performed by `class_addMethod` to be dramatically faster. Once that version is the predominant version of iOS for users of Realm we may want to reconsider the approach to `+className` as the tradeoffs involved will be different.\r\n\r\nFixes #3230."},"comment":{"url":"https://api.github.com/repos/realm/realm-cocoa/issues/comments/191138026","html_url":"https://github.com/realm/realm-cocoa/pull/3235#issuecomment-191138026","issue_url":"https://api.github.com/repos/realm/realm-cocoa/issues/3235","id":191138026,"user":{"login":"Changsung","id":2394181,"avatar_url":"https://avatars.githubusercontent.com/u/2394181?v=3","gravatar_id":"","url":"https://api.github.com/users/Changsung","html_url":"https://github.com/Changsung","followers_url":"https://api.github.com/users/Changsung/followers","following_url":"https://api.github.com/users/Changsung/following{/other_user}","gists_url":"https://api.github.com/users/Changsung/gists{/gist_id}","starred_url":"https://api.github.com/users/Changsung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Changsung/subscriptions","organizations_url":"https://api.github.com/users/Changsung/orgs","repos_url":"https://api.github.com/users/Changsung/repos","events_url":"https://api.github.com/users/Changsung/events{/privacy}","received_events_url":"https://api.github.com/users/Changsung/received_events","type":"User","site_admin":false},"created_at":"2016-03-02T08:58:56Z","updated_at":"2016-03-02T08:58:56Z","body":"Thanks for the fix! I already propose the idea to improve the launch: https://groups.google.com/forum/#!topic/realm-cocoa/Am71xzMGh-Q. "}}