Skip to content

Commit 9e7c8cd

Browse files
committed
docs: Document Zero-Allocation architecture in HeaderCanvas (#8652)
1 parent f17ae21 commit 9e7c8cd

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

apps/portal/canvas/HeaderCanvas.mjs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ const
2424
* - **Adaptive Geometry:** The strands flow loosely around text buttons but tighten into a "high-gravity orbit"
2525
* around social icons.
2626
*
27+
* **Performance Architecture (Zero-Allocation):**
28+
* To maintain 60fps on high-refresh displays without GC stutters, this class employs a **Zero-Allocation** strategy during the render loop.
29+
* 1. **TypedArray Buffers:** Wave geometry is stored in pre-allocated `Float32Array` buffers (`waveBuffers`), reused every frame.
30+
* 2. **Gradient Caching:** CanvasGradients are created only on resize (`updateResources`) and cached, avoiding expensive generator calls per frame.
31+
* 3. **Reusable Objects:** Physics calculations write directly to buffers instead of returning new Arrays of Objects.
32+
*
2733
* @class Portal.canvas.HeaderCanvas
2834
* @extends Neo.core.Base
2935
* @singleton
@@ -98,6 +104,8 @@ class HeaderCanvas extends Base {
98104
*/
99105
time = 0
100106
/**
107+
* Pre-allocated buffers for wave geometry.
108+
* Uses `Float32Array` to eliminate Garbage Collection pressure during the render loop.
101109
* @member {Object} waveBuffers={bgA: null, bgB: null, fgA: null, fgB: null}
102110
*/
103111
waveBuffers = {bgA: null, bgB: null, fgA: null, fgB: null}
@@ -218,11 +226,14 @@ class HeaderCanvas extends Base {
218226

219227
/**
220228
* Calculates the points for the two energy strands based on physics and interaction.
221-
* Writes directly to pre-allocated Float32Arrays to avoid GC.
229+
*
230+
* **Zero-Allocation Contract:**
231+
* This method writes directly to the pre-allocated `this.waveBuffers` `Float32Array`s.
232+
* It does **not** allocate new arrays or objects, ensuring zero GC pressure.
222233
*
223234
* @param {Number} width
224235
* @param {Number} height
225-
* @returns {Object} {shimmerA, shimmerB, count}
236+
* @returns {Object} {shimmerA, shimmerB, count} Metadata for rendering (scalars only)
226237
*/
227238
calculateStrandGeometry(width, height) {
228239
let me = this;

0 commit comments

Comments
 (0)