{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/litho/issues/385","repository_url":"https://api.github.com/repos/facebook/litho","labels_url":"https://api.github.com/repos/facebook/litho/issues/385/labels{/name}","comments_url":"https://api.github.com/repos/facebook/litho/issues/385/comments","events_url":"https://api.github.com/repos/facebook/litho/issues/385/events","html_url":"https://github.com/facebook/litho/pull/385","id":331890363,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk0NTA1NzM5","number":385,"title":"Cache and share LayoutState computation between threads","user":{"login":"vinc3m1","id":498852,"node_id":"MDQ6VXNlcjQ5ODg1Mg==","avatar_url":"https://avatars3.githubusercontent.com/u/498852?v=4","gravatar_id":"","url":"https://api.github.com/users/vinc3m1","html_url":"https://github.com/vinc3m1","followers_url":"https://api.github.com/users/vinc3m1/followers","following_url":"https://api.github.com/users/vinc3m1/following{/other_user}","gists_url":"https://api.github.com/users/vinc3m1/gists{/gist_id}","starred_url":"https://api.github.com/users/vinc3m1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vinc3m1/subscriptions","organizations_url":"https://api.github.com/users/vinc3m1/orgs","repos_url":"https://api.github.com/users/vinc3m1/repos","events_url":"https://api.github.com/users/vinc3m1/events{/privacy}","received_events_url":"https://api.github.com/users/vinc3m1/received_events","type":"User","site_admin":false},"labels":[{"id":526868498,"node_id":"MDU6TGFiZWw1MjY4Njg0OTg=","url":"https://api.github.com/repos/facebook/litho/labels/CLA%20Signed","name":"CLA Signed","color":"009900","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2018-06-13T08:22:31Z","updated_at":"2018-06-29T22:12:45Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/facebook/litho/pulls/385","html_url":"https://github.com/facebook/litho/pull/385","diff_url":"https://github.com/facebook/litho/pull/385.diff","patch_url":"https://github.com/facebook/litho/pull/385.patch"},"body":"This mitigates any duplicate layout that happens between the main and background threads while also caching the value as a result on a Future.\r\n\r\nThe existing behavior can be simplified to the following:\r\n- main thread -> measure() -> **calculateLayoutState()** -> mMainThreadLayoutState\r\n- bg thread -> calculateLayout() -> **calculateLayoutState()** -> mBackgroundLayoutState\r\n- **calculateLayoutState()** will then call the static function LayoutState.calculate() which eventually leads to calling the Components' @OnCreateLayout functions down the tree.\r\n- Eventually the mBackgroundLayoutState is copied over to mMainThreadLayoutState through backgroundLayoutStateUpdated() ->  setBestMainThreadLayoutAndReturnOldLayout()\r\n\r\nObviously a lot of details I'm leaving out, but that's the general gist. The important note here is that there are many subtleties in the code between the main and bg functions, intentional or not, that we don't want to inadvertently affect.\r\n\r\nThe issue we're seeing is that on initial layout calculateLayoutState() is often called twice for the same layout because the background threads don't finish calculating layouts and report them back to the main thread in time before the measure() function is called. Ironically, this seems exacerbated by expensive @OnCreateLayout calls, which are exactly the calls we don't want to duplicate during initial layout.\r\n\r\nThis change will share a FutureTask between main and bg threads that calculate the same layout (determined by LayoutStateFuture.equals()). That LayoutState will be also be cached on the Future until the next run with different params."},"comment":{"url":"https://api.github.com/repos/facebook/litho/issues/comments/401486852","html_url":"https://github.com/facebook/litho/pull/385#issuecomment-401486852","issue_url":"https://api.github.com/repos/facebook/litho/issues/385","id":401486852,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMTQ4Njg1Mg==","user":{"login":"vinc3m1","id":498852,"node_id":"MDQ6VXNlcjQ5ODg1Mg==","avatar_url":"https://avatars3.githubusercontent.com/u/498852?v=4","gravatar_id":"","url":"https://api.github.com/users/vinc3m1","html_url":"https://github.com/vinc3m1","followers_url":"https://api.github.com/users/vinc3m1/followers","following_url":"https://api.github.com/users/vinc3m1/following{/other_user}","gists_url":"https://api.github.com/users/vinc3m1/gists{/gist_id}","starred_url":"https://api.github.com/users/vinc3m1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vinc3m1/subscriptions","organizations_url":"https://api.github.com/users/vinc3m1/orgs","repos_url":"https://api.github.com/users/vinc3m1/repos","events_url":"https://api.github.com/users/vinc3m1/events{/privacy}","received_events_url":"https://api.github.com/users/vinc3m1/received_events","type":"User","site_admin":false},"created_at":"2018-06-29T22:12:45Z","updated_at":"2018-06-29T22:12:45Z","author_association":"CONTRIBUTOR","body":"Yeah that was an upstream build failure, rebased."}}
{"actor":{"display_login":"vinc3m1"}}