Skip to content

Can createElement be optimized for performance? #27216

@zackasaurus

Description

@zackasaurus

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution: StaleAutomatically closed due to inactivity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions