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

Use arrays for children? React.createElement #2351

Closed
syranide opened this issue Oct 15, 2014 · 2 comments
Closed

Use arrays for children? React.createElement #2351

syranide opened this issue Oct 15, 2014 · 2 comments

Comments

@syranide
Copy link
Contributor

I thought I'd bring this up before it's set in stone. Since React.createElement is intended mostly as a non-user feature as I understand it, wouldn't it make sense to take the opportunity to also change its signature to React.createElement(type, children) to avoid varargs for a potential perf boost.

Non-scientific test: http://jsperf.com/varargs/2

PS. Hmm, I guess we already support this... by simply providing only an array to children. But it seems that just touching arguments is a significant slow-down (relatively, not necessarily in practice).

cc @sebmarkbage

@plievone
Copy link
Contributor

But it seems that just touching arguments is a significant slow-down (relatively, not necessarily in practice).

There is a good overview of the arguments handling (in V8) here: https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#3-managing-arguments
Surprisingly, using Array.prototype.slice.call(arguments) leaks the arguments object, so it may be better to use an inline arguments slicer helper instead in very hot paths.

@sophiebits
Copy link
Contributor

createElement isn't only an internal API, we use arrays vs. varargs to distinguish child keys, and I believe these have been benchmarked to be comparable (or even faster with varargs?) so I'm going to close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants