-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Refactors component updates to minimize the number of string parsings… #1323
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
Conversation
|
can you add the issue number (#1311) to the commit message? |
8786b25 to
c6accf0
Compare
76aa778 to
beb8a71
Compare
|
This is the final design this patch has converged to:
|
|
The final gains for this patch on the included |
|
Things to look for when reviewing this patch. I like the perf benefits but I'm worried about the form. The complexity of the code to handle all the different cases is phenomenal. It's brittle and very difficult to understand. I cannot keep the complete flow in my head. This patch has been an effort of massaging the code until it covered all the edge cases. This work would not have been possible without the unit tests we have. There should be a simpler more concise way to express the same logic. I will keep thinking about ways to simplify. Bringing more eyes to this patch will help too. |
|
src/core/a-entity.js
Outdated
|
|
||
| component = this.components[name] = new components[name].Component(this); | ||
| if (this.isPlaying) { playComponent(component, this.sceneEl); } | ||
| // if (this.isScene && !this.hasAttribute(name) && name in this.defaultComponents) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can remove.
src/core/component.js
Outdated
| return utils.extend({}, data); | ||
| }, | ||
|
|
||
| updateCachedValue: function (value, isSinglePropSchema) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We call it cachedValue in one place and attrValue in another. Should we call it cachedAttrValue everywhere?
|
I made a big clean up. |
| <body> | ||
| <a-scene stats="true"> | ||
| <a-assets> | ||
| <a-mixin id="ball" geometry="primitive: sphere; radius:1" material="shader: flat; color: red"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space after radius radius: 1, extra space before material
|
r+wc |
|
Just checked with the editor and after some small changes everything works fine! I tried to inject |
… and component data stringifications (fixes aframevr#1311)
|
All right. I'm going to merge this monster patch. Demos seem to work. I feel better about code quality and it's also much faster :) |
|
Nice work 🎆 There're some unaddressed nits, but I can help with those if you want. |
|
I changed stuff after the last review. Everything should be addressed. |
|
GitHub shows some unaddressed diff lines, but not a big deal. |
Attributes updates is the most common operation in a-frame scenes. I've been looking for performance bottlenecks on setAttribute/getAttribute calls. Using the DOM to store the current state of the component incurs in a lot of component data stringifications (to feed the DOM attribute via HTMLElement.prototype.setAttribute) and parse calls to recalculate the component data from the attribute string or when getAttribute is called by the application logic. By caching the parsed attribute corresponding to the component we can save a lot of stringify/parse calls. The overhead is specially noticeable on scenes with a lot of dynamic behavior. I've added a stress test to illustrate the problem and show the performance gains. In the
stress-animationdemo I create a lot of elements with animations that will callsetAttributecontinuously. On my machine and without the patch the example runs in the lows-mids 20s FPS. With this patch applied it goes up to the lows-mids 30s FPS. That's approximately a 50% perf gain.