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

Optimize createElement() #2135

Merged
merged 5 commits into from
Nov 18, 2019
Merged

Optimize createElement() #2135

merged 5 commits into from
Nov 18, 2019

Conversation

developit
Copy link
Member

Avoiding shape mutation on props seems to give a 20% improvement in benchmarks.

props = assign({}, props);
let normalizedProps = {},
i;
for (i in props) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is clever

// Note: type may be undefined in development, must never error here.
if (typeof type === 'function' && type.defaultProps != null) {
for (i in type.defaultProps) {
if (typeof normalizedProps[i] === 'undefined')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we just do === undefined or is typeof cheaper?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe in this case we can use === yes, I actually was testing this and forgot to remove it.

Copy link
Member

@andrewiggins andrewiggins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

expect(<div />).to.have.property('key').that.is.undefined;
expect(<div a="a" />).to.have.property('key').that.is.undefined;
expect(<div />).to.have.property('key').that.is.empty;
expect(<div a="a" />).to.have.property('key').that.is.empty;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these assertions want to be .to.not.exist which would pass for null or undefined

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops, I literally read that in the docs and then wrote .empty. Tired me is tired!

Copy link
Member

@marvinhagemeister marvinhagemeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So good 🙌 ❤️

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 19e73bb on optimize-createelement into 9cf8cc7 on master.

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

Successfully merging this pull request may close these issues.

5 participants