Skip to content

Fix textWidth cache check and optimize segment style caching - #12295

Open
Zynviro wants to merge 3 commits into
chartjs:masterfrom
Zynviro:master
Open

Fix textWidth cache check and optimize segment style caching#12295
Zynviro wants to merge 3 commits into
chartjs:masterfrom
Zynviro:master

Conversation

@Zynviro

@Zynviro Zynviro commented Sep 2, 2026

Copy link
Copy Markdown

Description

This pull request introduces performance optimizations and a logic fix in canvas helpers:

  • src/helpers/helpers.canvas.ts: Updated the text width cache check in _measureText to use typeof textWidth === 'undefined' instead of a loose falsy check. This ensures a text width of 0 is properly stored rather than repeatedly forcing a re-measurement.
  • src/helpers/helpers.segment.js: Replaced an array .includes() lookup in the segment style cache replacer with a higher-performance Map implementation to optimize style serialization tracking.

Changes Made

  • Fixed conditional text width caching behavior.
  • Switched to a Map structure for tracking pattern/gradient style caching.
  • Cleaned up formatting and code readability across helper files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant