{"action":"created","issue":{"url":"https://api.github.com/repos/koreader/crengine/issues/130","repository_url":"https://api.github.com/repos/koreader/crengine","labels_url":"https://api.github.com/repos/koreader/crengine/issues/130/labels{/name}","comments_url":"https://api.github.com/repos/koreader/crengine/issues/130/comments","events_url":"https://api.github.com/repos/koreader/crengine/issues/130/events","html_url":"https://github.com/koreader/crengine/pull/130","id":306033409,"number":130,"title":"Optimize tinyNodeCollection::calcStyleHash()","user":{"login":"poire-z","id":24273478,"avatar_url":"https://avatars0.githubusercontent.com/u/24273478?v=4","gravatar_id":"","url":"https://api.github.com/users/poire-z","html_url":"https://github.com/poire-z","followers_url":"https://api.github.com/users/poire-z/followers","following_url":"https://api.github.com/users/poire-z/following{/other_user}","gists_url":"https://api.github.com/users/poire-z/gists{/gist_id}","starred_url":"https://api.github.com/users/poire-z/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/poire-z/subscriptions","organizations_url":"https://api.github.com/users/poire-z/orgs","repos_url":"https://api.github.com/users/poire-z/repos","events_url":"https://api.github.com/users/poire-z/events{/privacy}","received_events_url":"https://api.github.com/users/poire-z/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-03-16T18:29:11Z","updated_at":"2018-03-16T18:42:00Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/koreader/crengine/pulls/130","html_url":"https://github.com/koreader/crengine/pull/130","diff_url":"https://github.com/koreader/crengine/pull/130.diff","patch_url":"https://github.com/koreader/crengine/pull/130.patch"},"body":"(As noticed in https://github.com/koreader/koreader/pull/3740)\r\n`tinyNodeCollection::calcStyleHash()` is called on each rendering (at each page turn) to check nodes have not changed, so that previous rendering info can still be used.\r\nIt was looping thru all the nodes to compute some hash (each styles hash themselves are hopefully cached), which is really expensive (30% of page render time on a small book, 95% on a big book).\r\nAs nodes and their styles/fonts can only change at some occasions, it is best to use a cache for this computed value, that we reset only on such occasions.\r\nI'm quite certain nodes do not change except when we do an explicit re-rendering when some other stuff is changed (noticed by some of the other hashes change: default font, stylesheet...)  so we would even have no need to set `_nodeStyleHash = 0` as `ldomDocument::updateRenderContext()` would provoke a full re-rendering. But I added the `_nodeStyleHash = 0;` to all TinyNodeCollections methods that may modify the hash, just to have things proper.\r\n\r\nSimple page turn before:\r\n```\r\n03/16/18-19:18:02 DEBUG goto relative screen: 1 , in mode:  page\r\n03/16/18-19:18:02 DEBUG CreDocument: goto page 48\r\n2018/03/16 19:18:02.4487 TRACE LVDocView:Resize(600x610)\r\n2018/03/16 19:18:02.4488 TRACE Size is not changed: 600x610\r\n2018/03/16 19:18:02.4494 DEBUG Render(width=582, height=578, fontSize=19, currentFontSize=19, 0 char width=12)\r\n2018/03/16 19:18:02.4494 WARN Render is called for width 582, pageHeight=578, fontFace=Bitter, docFlags=15\r\n2018/03/16 19:18:02.4495 TRACE initializing default style...\r\n\r\n2018/03/16 19:18:02.4495 DEBUG calcStyleHash start\r\n2018/03/16 19:18:02.4495 DEBUG   CALCULATING _nodeStyleHash\r\n2018/03/16 19:18:02.5023 WARN Calculating style hash...  elemCount=382430, globalHash=4e94c012, docFlags=0000000f, nodeStyleHash=310750e9\r\n\r\n2018/03/16 19:18:02.5024 DEBUG calcStyleHash done\r\n2018/03/16 19:18:02.5024 WARN rendering context is not changed - no render!\r\n2018/03/16 19:18:02.5052 WARN 9784 rendered pages found\r\n2018/03/16 19:18:02.5052 DEBUG LVFontCache::gc() : 19 fonts still used, 0 fonts dropped\r\n2018/03/16 19:18:02.5053 DEBUG Updating selections...\r\n2018/03/16 19:18:02.5053 TRACE updateSelections() : selection count = 0\r\n2018/03/16 19:18:02.5053 DEBUG Render is finished\r\n2018/03/16 19:18:02.5083 DEBUG Loaded font ./fonts/noto/NotoSansCJK-Regular.ttf [0]: faceName=Noto Sans CJK SC,\r\n03/16/18-19:18:02 DEBUG refresh on physical rectangle -1 -1 602 612\r\n```\r\nafter:\r\n```\r\n03/16/18-19:07:20 DEBUG goto relative screen: 1 , in mode:  page\r\n03/16/18-19:07:20 DEBUG CreDocument: goto page 48\r\n2018/03/16 19:07:20.9390 TRACE LVDocView:Resize(600x610)\r\n2018/03/16 19:07:20.9390 TRACE Size is not changed: 600x610\r\n2018/03/16 19:07:20.9397 DEBUG Render(width=582, height=578, fontSize=19, currentFontSize=19, 0 char width=12)\r\n2018/03/16 19:07:20.9398 WARN Render is called for width 582, pageHeight=578, fontFace=Bitter, docFlags=15\r\n2018/03/16 19:07:20.9398 TRACE initializing default style...\r\n\r\n2018/03/16 19:07:20.9398 DEBUG calcStyleHash start\r\n2018/03/16 19:07:20.9398 DEBUG   using saved _nodeStyleHash\r\n2018/03/16 19:07:20.9399 WARN Calculating style hash...  elemCount=382430, globalHash=4e94c012, docFlags=0000000f, nodeStyleHash=310750e9\r\n2018/03/16 19:07:20.9399 DEBUG calcStyleHash done\r\n\r\n2018/03/16 19:07:20.9399 WARN rendering context is not changed - no render!\r\n2018/03/16 19:07:20.9452 WARN 9784 rendered pages found\r\n2018/03/16 19:07:20.9452 DEBUG LVFontCache::gc() : 23 fonts still used, 0 fonts dropped\r\n2018/03/16 19:07:20.9452 DEBUG Updating selections...\r\n2018/03/16 19:07:20.9453 TRACE updateSelections() : selection count = 0\r\n2018/03/16 19:07:20.9453 DEBUG Render is finished\r\n03/16/18-19:07:20 DEBUG refresh on physical rectangle -1 -1 602 612\r\n```\r\nIt is only 50ms gain on the emulator, but it's probably ~500ms on a device, which is enough to give a feeling of a small boost (and more page turns per battery % :)\r\n"},"comment":{"url":"https://api.github.com/repos/koreader/crengine/issues/comments/373808345","html_url":"https://github.com/koreader/crengine/pull/130#issuecomment-373808345","issue_url":"https://api.github.com/repos/koreader/crengine/issues/130","id":373808345,"user":{"login":"Frenzie","id":202757,"avatar_url":"https://avatars2.githubusercontent.com/u/202757?v=4","gravatar_id":"","url":"https://api.github.com/users/Frenzie","html_url":"https://github.com/Frenzie","followers_url":"https://api.github.com/users/Frenzie/followers","following_url":"https://api.github.com/users/Frenzie/following{/other_user}","gists_url":"https://api.github.com/users/Frenzie/gists{/gist_id}","starred_url":"https://api.github.com/users/Frenzie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Frenzie/subscriptions","organizations_url":"https://api.github.com/users/Frenzie/orgs","repos_url":"https://api.github.com/users/Frenzie/repos","events_url":"https://api.github.com/users/Frenzie/events{/privacy}","received_events_url":"https://api.github.com/users/Frenzie/received_events","type":"User","site_admin":false},"created_at":"2018-03-16T18:42:00Z","updated_at":"2018-03-16T18:42:00Z","author_association":"OWNER","body":"lol, looks like you somehow broke cppcheck :-P\r\n\r\n> Error while processing /home/travis/build/koreader/crengine/crengine/include/lvtinydom.h"}}
{"actor":{"display_login":"Frenzie"}}