You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
The identity of React elements (objects with a properly configured $$typeof property) is immaterial.
We can therefore identify structurally equivalent react elements, ultimately resulting in improved code density.
Action plan:
Rewrite the heap to identify structurally equivalent react elements, e.g. in the ResidualHeapVisitor, by maintaining a new HashSet containing wrapper objects around react elements that implement a structural getHash and equals.
(Note that as a result, a react element may now appear in multiple scopes.)
For children of react elements, the serializer currently has a special treatment in _serializeValueReactElementChild: it bypasses the regular logic of serializeValue that hands out names to values and selects the proper target body. This needs to get revisited. One approach would be to just fall back to the regular code path. This would result in aesthetically displeasing code, unless the option --inlineExpressions is given; however, when combined with an JavaScript compiler that produces bytecode, the resulting bytecode is likely the same even without --inlineExpressions.
The reason _serializeValueReactElementChild currently does what it does is to add keys to array elements. However, @trueadm has a plan how to switch from arrays to fragments which no longer have that requirement. We'll probably need that first.
The text was updated successfully, but these errors were encountered:
trueadm
changed the title
De-dupe JSC elements when serializing
De-dupe JSX elements when serializing
Nov 14, 2017
One constraint to add, if the JSX attribute of key is a StringValue we cannot add these de-dupe optimizations to that React element as this depends on React runtime constraint. Check this issue for prior discussions on this topic: facebook/react#3226
Summary:
After adding some tests, it turns out that logic to apply keys to arrays was un-needed. This was because, after running the same code through React, the same errors occur when keys are omitted from arrays. We don't need to do any clever tricks to add keys, as it might actually break logic on things that don't need them. I've added the relevant tests and removed the key adding logic, which should help us with the de-duping work (#1150).
Closes#1151
Differential Revision: D6323878
Pulled By: trueadm
fbshipit-source-id: ec3fa90c48332ef0715e94335c558570040ed81c
The identity of React elements (objects with a properly configured $$typeof property) is immaterial.
We can therefore identify structurally equivalent react elements, ultimately resulting in improved code density.
Action plan:
(Note that as a result, a react element may now appear in multiple scopes.)
The reason
_serializeValueReactElementChild
currently does what it does is to add keys to array elements. However, @trueadm has a plan how to switch from arrays to fragments which no longer have that requirement. We'll probably need that first.The text was updated successfully, but these errors were encountered: