Skip to content

Improve performance of mergeReactProps - #456

Merged
atomiks merged 1 commit into
mui:masterfrom
marcpachecog:improve-performance-of-merge-react-props
Jun 14, 2024
Merged

atomiks merged 1 commit into
mui:masterfrom
marcpachecog:improve-performance-of-merge-react-props

Conversation

@marcpachecog

Copy link
Copy Markdown
Contributor

The mergeReactProps function uses a regex to identify event handlers and invoke them all. Since it is a low-level utility, I believe it should be optimized for performance, even at the expense of some readability.

Just suggesting an alternative approach that doesn't rely on using a regex.

@mui-bot

mui-bot commented Jun 12, 2024

Copy link
Copy Markdown

Netlify deploy preview

https://deploy-preview-456--base-ui.netlify.app/

Generated by 🚫 dangerJS against 6325945

@atomiks

atomiks commented Jun 13, 2024

Copy link
Copy Markdown
Contributor

Thank you for the PR!

However it seems like they're practically identical in performance to the point that the bundle size cost would instead be the more impactful trade-off?

@marcpachecog

marcpachecog commented Jun 13, 2024 •

Copy link
Copy Markdown
Contributor Author

@atomiks This can be true for high-end devices, especially in desktop environments (in my case, regex is about 20% slower). However, the drop in performance is much more noticeable on mobile devices. In a large app, this regex might be invoked hundreds or even thousands of times, making this optimization potentially worthwhile.

339237249-a0f67ad4-17b4-46ea-8166-ec07a6ef4ed2.mov

@michaldudak

Copy link
Copy Markdown
Member

Testing on my machine shows that the regex is ~30% slower on average, so IMO it is worth merging.

@atomiks

atomiks commented Jun 13, 2024

Copy link
Copy Markdown
Contributor

@marcpachecog ok seems fine to me then!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants