Repository navigation
Speed up CPU touching and colour queries - #10
Merged
Merged
Conversation
Touching sprite and touching colour spent most of their time in generic per-point calls: a matrix lookup, an effect check and three levels of method dispatch for every pixel. Drawables with a standard skin and no shape-changing effect now go through inlined loops that read silhouette data directly. The arithmetic is the same as getLocalPosition, including float32 rounding, so results are bit-for-bit identical. Custom skins, custom silhouettes and fisheye, whirl, pixelate and mosaic keep the generic path. Candidate collection caches each drawable's integer bounds until its transform or hull changes, rejects non-overlapping drawables before the skin checks, and reuses candidate records instead of allocating one per overlap. Smaller SVG MIPs are rasterised on a shared scratch canvas, so creating one no longer forces the silhouette to read back the skin's own canvas. Version 0.1.0 to 0.1.1.
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.
Touching sprite and touching colour are the renderer's share of script time in sprite-heavy projects. This makes both several times cheaper without changing a single result.
What changed
isTouchingDrawablesandisTouchingColorused to make a generic call per pixel per drawable: inverse matrix lookup, effect check, then skin and silhouette dispatch. Drawables with a standard skin and no shape-changing effect now go throughDrawable.isTouchingPair,Drawable.isTouchingPlainandDrawable.samplePlainColor4b, which read silhouette data directly. The arithmetic is the same asgetLocalPosition, including the float32 rounding and the 1e-6 snap. Custom skins, custom silhouettes and fisheye, whirl, pixelate and mosaic keep the generic path. Ghost, colour and brightness do not move pixels, so they stay on the fast path.No public
RenderWebGLmethod changed name or signature. Shader sources are untouched.Results
Script time on the scratch-bench real-project replays (Chromium on SwiftShader, frame by frame against TurboWarp, same MistWarp VM before and after):
Every state checkpoint of all twelve replays still hashes the same as TurboWarp.
How it was checked
isTouchingDrawables,isTouchingColor(with and without a mask) anddrawableTouchingqueries across Chromium, Firefox and WebKit, zero differences.test/unit/TouchingFastPathTests.jscompare each fast path with the generic one, including the fallbacks.npm run lint, the conventions check,npm run buildandnpm run testpass.Version 0.1.0 to 0.1.1.
Nothing visible changes, so there are no screenshots.