Skip to content

feat: optimize graph rendering performance and improve animation hand…#8

Merged
pphatdev merged 1 commit intolatestfrom
feat-graph
Feb 21, 2026
Merged

feat: optimize graph rendering performance and improve animation hand…#8
pphatdev merged 1 commit intolatestfrom
feat-graph

Conversation

@pphatdev
Copy link
Copy Markdown
Owner

This pull request refactors the GraphRenderer class in src/components/graph-renderer.ts to optimize performance and improve code readability. The main changes include moving static constants out of hot code paths, pre-computing scale-dependent values, and replacing array allocations with more efficient loops and flat push patterns. These updates reduce unnecessary allocations and repeated calculations, making the rendering logic faster and easier to maintain.

Performance and allocation optimizations:

  • Moved static constants (SIZE_PRESETS, MONTHS, lerp arrays) to class-level properties to avoid repeated allocation and prototype lookups in hot code paths.
  • Replaced repeated Math.round calculations with pre-computed, scale-dependent constants (e.g., sc14, sc42) and used these throughout the rendering logic for font sizes, positions, and dimensions. [1] [2] [3]
  • Converted cell and star rendering from nested Array.map and Array.from to flat push loops, reducing intermediate array allocations and improving performance for large graphs. [1] [2]

Rendering logic improvements:

  • Pre-computed position and delay format strings for cell rendering, avoiding repeated .toFixed calls inside loops.
  • Optimized month label rendering by using fast string slicing for date parsing instead of constructing Date objects.

SVG structure and animation improvements:

  • Simplified SVG animation code by pre-computing animation strings per column and binding static lerp arrays to local variables for faster access.
  • Updated grid lines and legend rendering to use plain for-loops and pre-computed constants, further reducing allocation overhead.…ling

@pphatdev pphatdev merged commit 80dd869 into latest Feb 21, 2026
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