Optimization of Body's hidden class #528
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I noticed that the number of properties on the bodies were not always the same. It varied between 45 and 48. Which is bad for performance as the JS compiler and optimizer cannot take advantage of consistent hidden classes when compiling JS code.
That is to say, having different number of properties per body meant that the optimizer could not optimally optimize some methods (apparently the most unoptimized methods were
solverVelocity
andBody.update
).Changes
Body.set
method as it was never called with a string as a 2nd argument.Results
The gain is especially high on test using mixed shapes where more than 2 hidden structures had to be supported. The following benchmark was done on the
Mixed Shape
test:Before
After
On a fairly similar profiling duration we can notice that the consumption of the engine is about 25% lower after the optimization!
Gains are usually not that high and seem to indicate a performance boost of 10% in most cases.
Note: Taking a memory snapshot both before and after seemed to indicate that the memory footprint increase was unnoticeable:
(Snapshot 4 is before and Snapshot 5 after)