facebook/react — pull request #1547 by syranide (2014-05-17 15:57:31+00:00)
Title: Proof-of-concept, relative react IDs

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 the `data-reactid` attribute and immediately traversing the DOM to 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 `DOM node <=> ReactDOMComponent`.

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).