Repository navigation
Cut the renderer's cost per sprite move, costume switch and pen line - #11
Merged
Merged
Conversation
A skin kept the drawables using it in a Set, so every costume switch paid for a hash delete and a hash add. It is now an array with each drawable remembering its slot. Pen lines grew the dirty box with eight Math.min and Math.max calls per line. They are now plain comparisons. Fencing recomputed the drawable's transform and bounds on every move. The bounds are now remembered until the sprite changes shape, and a move that stays clearly inside the stage returns without recomputing them. Moves near the edge still take the exact path.
The remembered state is now the box of positions that are free of the fence, so the check on a move is four comparisons. A sprite whose bounds cannot be measured, such as one with an infinite size, is never fenced and is remembered as free everywhere. The margin is sized for the 32-bit model matrix, positions beyond 10000 drop the memory, and a change of stage size is noticed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Three per-call costs in the renderer that showed up on the real-project replays. With the same VM, this fork's renderer was 10% slower than TurboWarp's on Game of Life and 4.5% slower on Doom. None of the three changes what is drawn or what any query returns.
What changed
Set, so every costume switch paid for a hash delete and a hash add. It is now an array, and each drawable remembers its slot in it.Math.minandMath.maxcalls. They are now comparisons. A line with a coordinate that is not a number marks the whole layer dirty, so the read back is never skipped.Version 0.1.1 to 0.1.2.
Speed
Paired replays with hardware counters, three rounds, every state hash agreeing, same VM on both sides (scratch-vm scratchfoundation#55). Ratios are develop's renderer over this branch, so above 1 is faster.
The other six replays are within noise (CPU 0.985 to 1.021). Against TurboWarp (its own VM and renderer) every replay is now at least 1.05x on CPU, with a geomean of 1.44x over all 12. Game of Life was the one replay still behind TurboWarp (0.92x at the same checkpoint) and is now 1.05x. The TurboWarp comparison was run on the commit before the last one, which only adds the guard for coordinates that are not numbers.
Checks
test/unit/FencingTests.js: fencing with and without the memory compared over 100,000 random moves, scales, rotations, skin changes and quality switches, plus 18,000 moves placed within a few millionths of the fence from random starting points. Results are identical. Further tests cover far-away and endless positions, unmeasurable bounds, stage resizes, skins with their own fence bounds, and that moves inside the stage skip the bounds. 18 mutants of the new fencing code are caught. One more, dropping the fixed slack, changes nothing because the rounding margin already covers it.test/unit/PenDirtyRegionTests.js: the dirty box against the oldMath.minandMath.maxform for lines in every direction and 200 random lines, the partial read back, and the full read back for coordinates that are not numbers.test/unit/SkinLifecycleTests.js: a skin tracks exactly the drawables that use it through switches and disposal.npm run lint,npm run tap,npm run buildandnpm run check:conventionspass.No visible surface, so no screenshots.