-
Notifications
You must be signed in to change notification settings - Fork 46.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimizing Compiler: Tagging ReactElements #3227
Comments
This seems problematic with watcher builds and generally keeping bundle hashes static for production. Or is this intended to be a production build post-process of some sort? But even then there are problems when separate parts of apps are built/maintained individually.
This would be very useful for non-DOM elements too I would think (but it would have to be opt-in).
It seems to me that you would also want
Shouldn't this be globally per |
cc @jimfb |
@sebmarkbage why not instead use the hidden class object to reference var t = { children: 1, style: { width: 1 } };
{ __t: t, type: 'div', props: { className: 'foo', style: { width: w, height: 5 }, children: c } } Then you'd easily be able to loop through only these props upon doing a patch of the You could go one step further (would affect backwards compatibility) and make the original ReactElement only return dynamic props plus the hidden class reference. The hidden class would reference all the static props. Furthermore, you can work out what is static at compile time, depending on how much computation time you want to spend in the compilation stage, for example the following would return as static:
There are plenty more too, but those are the easy ones to find in the AST. |
@trueadm I think @sebmarkbage mentioned that originally with "Bonus points if we can determine which properties are constant.". |
@spicyj wasn't that referring to the hidden class only referencing props that were constant/static? Sorry, maybe I misunderstood what point of mine you were referencing. |
Oh, I totally misread. You're right, my apologies. |
We can make more optimized reconciliation by tagging ReactElements with the "hidden class" of their props.
For example, this is guaranteed to always have three props:
className
,width
,children
.If we could tag every element with these properties with a unique ID:
Then we could use the hidden class to generate an optimized diffing algorithm for these instead of iterating over the properties. Presumably, we would only need to do this for
type: <string>
since we only diff native components.Bonus points if we can determine which properties are constant. Perhaps using a property descriptor object:
We would use a heuristic inside React to determine when to create an optimized differ. For example, after 10+ updates to the same component. Just like a JIT would do.
The text was updated successfully, but these errors were encountered: