-
Notifications
You must be signed in to change notification settings - Fork 328
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
Cache and don't re-create transformed hull points #445
Cache and don't re-create transformed hull points #445
Conversation
41f1bbb
to
a9477e2
Compare
a9477e2
to
a24929a
Compare
a24929a
to
75a4792
Compare
const projection = twgl.m4.ortho(-1, 1, -1, 1, -1, 1); | ||
const skinSize = this.skin.size; | ||
const halfXPixel = 1 / skinSize[0] / 2; | ||
const halfYPixel = 1 / skinSize[1] / 2; | ||
const tm = twgl.m4.multiply(this._uniforms.u_modelMatrix, projection); | ||
const transformedHullPoints = []; |
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.
Have you verified that callers never modify the contents of the array returned by this function?
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.
_getTransformedHullPoints
is called by getBounds
and getBoundsForBubble
.
getBounds
passes it to Rectangle.initFromPointsAABB
which does not modify the array.
getBoundsForBubble
calls map
and filter
on the array, both of which create new arrays instead of modifying in-place.
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.
👍
Resolves
OneTwo of the concerns in #365Proposed Changes
Rectangle
s per-Drawable
for holdingget(Fast)Bounds
resultsReason for Changes
Rectangle
s per-Drawable
for holdingget(Fast)Bounds
resultsDrawable.getBounds
,Drawable.getBoundsForBubble
,Drawable.getFastBounds
, andDrawable.getAABB
take an optionalresult
parameter (aRectangle
). If given, it will be set to the drawable's bounds.If a
result
parameter was not passed, however, those functions would create an entirely newRectangle
on each call. To make things worse, they're called from several places in the codebase without aresult
being passed.Now, each
Drawable
instantiates its ownRectangle
s to hold the bounds results only once: when theDrawable
itself is created. This should prevent unnecessary creation ofRectangle
s.Previously, calling
_getTransformedHullPoints
would result in an entirely new array being created and filled up withtwgl.v3
objects each time.Now, the array is created and filled with
twgl.v3
objects only when the convex hull itself changes._getTransformedHullPoints
now modifies thesetwgl.v3
objects in-place. This change should greatly reduce the number of unnecessary objects created.Previously, calling
_getTransformedHullPoints
meant always recalculating the positions of transformed convex hull points. Now, they are only recalculated when the transform has actually changed.These changes greatly reduce the allocations made by convex-hull functions:
"Vector scaling performance test 2" (makes heavy use of "if on edge, bounce")