Centralise 2D rendering context managements - #2825
Open
Desplandis wants to merge 2 commits into
Open
Conversation
Desplandis
force-pushed
the
perf/canvas2D
branch
3 times, most recently
from
August 4, 2026 15:15
1d4231a to
f6d3475
Compare
Desplandis
force-pushed
the
perf/canvas2D
branch
from
August 4, 2026 15:23
f6d3475 to
1afd28b
Compare
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.
Description
This PR introduces a new
CanvasUtilsmodule that centralises the creation and management of 2D rendering contexts. It provides three helper functions covering the main usage patterns in the codebase:The utilities intentionally return rendering contexts rather than canvases. This avoids a browser behavior where calling
getContext()multiple times with different initialization options always returns the first-created context, ignoring subsequent parameters. This issue already existed in the codebase before this PR.As part of this refactor, I also removed several unnecessary
willReadFrequentlycontext initialisations. Those contexts never performed read operations, so dropping the flag improves performance (20% to 6% CPU usage in a MVT example, hard to quantify without proper benchmarking...).Additionally, icon tinting has been reworked. The previous per-pixel
replaceWhitePxlimplementation as been replaced with a canvas compositing approach (multiply&destination-in). This solution is simpler, faster since this is canvas-only, and allows removingRenderer/Color.js.