LearnNewsExamplesServices
Frontmatter
id8651
titleOptimize HeaderCanvas Rendering (GC & Gradients)
stateClosed
labels
airefactoringperformance
assigneestobiu
createdAtJan 14, 2026, 8:32 PM
updatedAtJan 14, 2026, 8:36 PM
githubUrlhttps://github.com/neomjs/neo/issues/8651
authortobiu
commentsCount1
parentIssue8630
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtJan 14, 2026, 8:36 PM

Optimize HeaderCanvas Rendering (GC & Gradients)

Closed v11.22.0 airefactoringperformance
tobiu
tobiu commented on Jan 14, 2026, 8:32 PM

Optimize apps/portal/canvas/HeaderCanvas.mjs to reduce Garbage Collection (GC) pressure and improve rendering performance, inspired by the efficiency of TicketCanvas.mjs.

Identified Issues:

  1. Object Allocation Churn: calculateStrandPoints and drawAmbientBackground allocate new arrays and thousands of {x, y} object literals every frame (60fps). This causes significant GC overhead.
  2. Redundant Gradient Creation: createLinearGradient is called every frame with identical parameters (0 to width), creating unnecessary objects.

Optimization Plan:

  1. Gradient Caching: Move gradient creation to updateSize (or lazy-init with cache). Recreate only when dimensions change.
  2. TypedArray Buffers: Replace array-of-objects with Float32Array buffers to store wave geometry.
    • Implement this.waveBuffer (e.g., holding Y values).
    • Reuse these buffers every frame, eliminating per-frame object allocation entirely for the main loops.

Target: Zero per-frame allocation for the core render loop.

tobiu added the ai label on Jan 14, 2026, 8:32 PM
tobiu added the refactoring label on Jan 14, 2026, 8:32 PM
tobiu added the performance label on Jan 14, 2026, 8:32 PM
tobiu added parent issue #8630 on Jan 14, 2026, 8:32 PM
tobiu referenced in commit f17ae21 - "perf: Optimize HeaderCanvas rendering (GC and Gradient caching) (#8651)" on Jan 14, 2026, 8:35 PM
tobiu assigned to @tobiu on Jan 14, 2026, 8:35 PM
tobiu
tobiu Jan 14, 2026, 8:35 PM

Input from Gemini 3 Pro:

✦ Refactored HeaderCanvas for maximum performance:

  1. Gradient Caching: Gradients (grad1, bgRibbon, etc.) are now cached in this.gradients and only recreated on resize, instead of every frame.
  2. Zero-Allocation Loop: Replaced per-frame {x, y} object allocation with Float32Array buffers (this.waveBuffers) for wave geometry. This eliminates thousands of objects per second from the GC cycle.
  3. Refactored Logic: Updated calculateStrandGeometry and drawAmbientBackground to write directly to these buffers.

This brings HeaderCanvas up to the high-performance standard of TicketCanvas.

tobiu closed this issue on Jan 14, 2026, 8:36 PM