-
Notifications
You must be signed in to change notification settings - Fork 47.6k
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
[performance] Remove hasOwnProperty calls to objects that are managed within React #5504
Conversation
878061c
to
9e55c58
Compare
@mridgway updated the pull request. |
9e55c58
to
8cbe199
Compare
@mridgway updated the pull request. |
The failing test was added in af7e432 but doesn't seem to be testing the right thing. In this case the |
In what engine? Conveniently, I just put up some benchmarking scripts earlier today in #5503. I just ran them and this seems ~1–3% faster in jsc (depending on exactly which number you look at) but slower in node. Not sure why. In any event, this is a behavior change because we had intended to not crash on inputs like |
Primarily, IE8 doesn't have a concept of non-enumerable keys, so all keys are iterated. So to support IE8 you must use this in for-loops. Having keys with names such as The only other problem is broken setups where someone has done |
@syranide I'm having trouble parsing your comment. What I meant was
will not copy Like most libraries (e.g., all versions of jQuery), we don't support adding keys to Object.prototype. |
I specifically did not remove the |
|
Ah, got it. |
This discussion came up in another PR I submitted as well: #3665. Usage of |
How did you benchmark? |
I haven't run benchmarks yet. I was using the v8 profiler to identify top CPU usage. Working on getting my old benchmark.js suite working with React 14 now. |
this might be dangerous with IE8, particularly if methods are added to Object.prototype by old MooTools or Prototype versions, which wouldn't be in a defined |
Using profiling
hasOwnProperty
goes from 3.7% of ticks to 0.6% of ticks when callingrenderToStaticMarkup
10,000 times. I made sure to only remove calls when the objects are internally created and managed and guaranteed to never have prototypes.I've also been thinking about optimizations for
props
. By ensuring that props are a prototype-free object early on inReact.createElement
a lot of thehasOwnProperty
checks downstream could be optimized. I think this may get in to micro-optimization territory though since I'm only seeing 0.6% of ticks inhasOwnProperty
at this point (although paths other thanrenderToStaticMarkup
may have more usage like the reconciler).