Add helpers for tracking subtree staticness inside h functions#140
Merged
jviide merged 2 commits intodevelopit:masterfrom Jan 21, 2020
jviide:staticness-bits
Merged
Add helpers for tracking subtree staticness inside h functions#140jviide merged 2 commits intodevelopit:masterfrom jviide:staticness-bits
h functions#140jviide merged 2 commits intodevelopit:masterfrom
jviide:staticness-bits
Conversation
Owner
|
Having a firm indicator that the callsite matches could almost make recycling viable again. It wouldn't have the issue of recycling trees across usages, instead only ever recycling stuff that was used at the same callsite (render --> unrender --> re-render) |
developit
approved these changes
Jan 21, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request modifies the
evaluatefunction by adding more granular tools for tracking the staticness of a vnode and its children inside ahfunction.HTM already automatically tracks and caches completely static subtrees (see #132). The tracking & caching process is completely transparent for the
hfunction. That being said, there are still some hypothetical optimization possibilities ifhfunctions got some more (optional) information. For example, vnodes with static props but some dynamic children would not fall under the "completely static subtree" umbrella that #132 optimizes. A VDOM-based UI framework could still use that staticness information to skip diffing such nodes and jump directly into diffing their children.This PR adds two tools for exploring such optimization possibilities:
The
thisvariable insidehfunction calls are now set to an object that is bound to thehtmlfunction call site and position inside the tagged template string. For example in the following case thethisvalue stays the same:For different call sites and different
hfunctionsthischanges:this[0]inside anhfunction call is a number, tracking the staticness of the currently created vnodes.If the number's lowest bit is set then the vnode being created depends on dynamic values, but its children may or may not be dynamic. If the second-lowest bit is set then some of the vnode's children depend on dynamic values, but the vnode itself may or may not be dynamic.
By that same logic, when the two lowest bits are both zeroes then the whole subtree rooted to the current vnode is static (and HTM will cache it). When the two lowest bits are both set then both the vnode and some of its children are dynamic.
These two features can be used in conjunction to e.g. annotate created vnodes with optimization information. For example,
thiscould be stored in the created vnode's._callsiteproperty. Later, when two vnodes are diffed against each other, the diffing function could check whether their._callsiteproperties are set and strictly equal and_callsite[0]'s lowest bit is set, and skip diffing the vnodes and move on to their children. In iffy pseudocode:With these changes HTM's overall performance seems to stay the same.
htm.module.js.brsize grows by 7 bytes (from 570 B to 577 B).