Proof-of-concept, relative react IDs #1547
Closed
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.
cc @petehunt
I did a quick take on it to see what the outcome was, so here it is, each node only has a relative ID. Having to traverse up the tree to reconstruct the key is significantly expensive though (not surprisingly). The only two ways out of that is to cache the reconstructed key in each node traversed (ick) or to use an absolute ID at say custom component roots, which would significantly limit the depth.
Results: http://i.imgur.com/EzkzZkp.png
As you can see, two of the tests has taken a significant hit, presumably from
ReactMount.getID
becoming significantly more expensive due to having to reconstruct the ID. Expectedly though, the brute renderComponent test shows a significant ~11% improvement, presumably from the significantly shorter HTML generated.Having run some basic performance tests on [mounting + unmounting], and [mounting + traversing + unmount], it doesn't seem like there's a significant cost to traverse all inserted nodes. Given that
data-reactid
actually seems to add a measurably significant cost during insertion into the DOM, I'm feeling confident that removing thedata-reactid
attribute and immediately traversing the DOM would compete in performance. It would also bring with it a bunch of other significant benefits; all DOM components already have a ref to its node, less DOM clutter, less bloat for server-rendered DOM, etc.I'm not familiar enough with the core, but intuitively it seems like traversing the inserted DOM and renderedComponents in sync should be fairly straight-forward. Additionally, since we're traversing the DOM, rather than invent a react ID at all, it seems like it should be enough to just put a "hidden" reference directly to each DOM component in each node. You now have a super cheap
DOM node <=> ReactDOMComponent
. Additionally, we would no longer need to maintain thenodeCache
either.Perhaps there are technical issues standing in the way, but it would seem like the same information could also be used in
DOMChildrenOperations
to remove the dependency on_mountIndex
, which would be a very good thing (but perhaps it's just wishful thinking).