Skip to content
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

Can createElement be optimized for performance? #27216

Closed
zackasaurus opened this issue Aug 11, 2023 · 2 comments
Closed

Can createElement be optimized for performance? #27216

zackasaurus opened this issue Aug 11, 2023 · 2 comments
Labels
Resolution: Stale Automatically closed due to inactivity

Comments

@zackasaurus
Copy link

For large complex apps that have many props and a deep react DOM tree, createElement is one of the most expensive operations.

I've noticed for large complex apps such as Facebook and Discord, createElement can take up 10% of the memory allocation during a basic scenario, and it can take up 2-5% of the script time, not accounting for MajorGC and MinorGC.

The issue is that the props object in createElement gets created from scratch, and the entire config that's passed in gets iterated over. Since the config object isn't used anymore after createElement, it gets marked for GC, which additionally hurts performance.

I have an idea where we can just simply assign props to config for most cases, such as when the props object is not frozen, and no key or ref was passed in to createElement. I can create a PR, but I wanted to run it by the react devs first to see if there is anything I'm missing.

Facebook

Screenshot 2023-08-11 at 11 25 34 AM Screenshot 2023-08-11 at 11 25 43 AM Screenshot 2023-08-11 at 11 24 49 AM

Discord

Screenshot 2023-08-11 at 11 17 39 AM Screenshot 2023-08-11 at 11 17 57 AM
Copy link

github-actions bot commented Apr 7, 2024

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

@github-actions github-actions bot added the Resolution: Stale Automatically closed due to inactivity label Apr 7, 2024
@sophiebits
Copy link
Contributor

Thanks for filing this! This helped kick-start the work to get #28768 and friends landed for real. Hopefully you will see even larger gains from that set of changes once they’re released (note they’re still behind a feature flag on main for now).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Stale Automatically closed due to inactivity
Projects
None yet
Development

No branches or pull requests

2 participants