-
Notifications
You must be signed in to change notification settings - Fork 349
Initialialize AABB Rectangle #467
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
Initialialize AABB Rectangle #467
Conversation
6fddfc0
to
447923a
Compare
- pass bounds as a destination parameter - add initFromMatrixRadius - use initFromMatrixRadius in getAABB
447923a
to
3b2cd5f
Compare
3b2cd5f
to
116e4a6
Compare
116e4a6
to
5886622
Compare
5886622
to
5d7957f
Compare
How does this compare to what I did in #445? |
@adroitwhiz I think #467 and #445 go together. We won't need to cache vectors for getAABB after #467, but we'll still need to cache vectors for getTransformedHullPoints. Probably still use #467 |
I've moved the math proof documentation into a jsdoc tutorial at |
ba99c58
to
994e9be
Compare
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.
👍
Extra thanks for documenting the math behind this!
Resolves
Render related VM performance, such as fencing a sprite inside the scratch canvas.
Proposed Changes
Reason for Changes
Current getAABB creates 4 3D vectors, transforms them by a 4x4 matrix and compares their axes to find the left, right, top, bottom extremes for the AABB. We can break that down into something like 2 function calls, 21 object member reads, 6 writes, 15 mulitplications, 13 additions, 2 created objects, and 5 comparisons per vectors. That is 64 operations per vector. Or 256 operations to construct the AABB.
This version by comparisons uses 6 object members reads, 6 multiplications, 6 additions, and 4 absolute value operations. In total that is 22 operations to construct the AABB.
The main cause in the difference in operations is that the current version transforms 4 vectors, and this version transform the 1 vector into the absolute value of its transformed components. Then the work is further reduced by contraining the transformation to 2 dimensions.
Passing a Rectangle to getBounds functions lets us reuse Rectangles to avoid creating lot of garbage that needs to be cleaned up. By chance we can't reuse a rectangle the functions can create their own to return.
Test Coverage
The existing Drawable units that test getAABB.
Benchmark Data
Chrome inspector
This table was collected from the Chrome Inspector's Javascript Profiler tab running the 14844969 benchmark. The values in this table are the percent of time spent under getFastBounds, which is used by SVGSkin to get the getFenceBounds to calculate the fence position when moving a sprite with motion_changex and other blocks. The values do not add up to 100 as many of the functions are nested in another.
Some columns do not report any time spent. getAABB and copy are still being called, but time spent there was not captured by the profiler.
scratch-vm benchmark
The following values were collected the scratchfoundation/scratch-vm#2196 change on scratch-vm.
Highlights
These highlighted benchmarks heavily use motion blocks that depend on the changed code.
edit: The before times in this table by accident do not reflect develop. This means the comparison has increased noise. I am leaving the table here for recording repurposes. This does not affect the chrome inspector table.
Full Benchmark Suite
This is a table of the benchmarks with one run each for project id, vm state, device, before and after. As such the noise to signal ratio is high here, so there is a high margin of error in the amount performance changed. Most of the identifiable correlation is in the above highlights table.
edit: The before times in this table by accident do not reflect develop. This means the comparison has increased noise. I am leaving the table here for recording repurposes. This does not affect the chrome inspector table.