|
24 | 24 | * - **Adaptive Geometry:** The strands flow loosely around text buttons but tighten into a "high-gravity orbit" |
25 | 25 | * around social icons. |
26 | 26 | * |
| 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 | + * |
27 | 33 | * @class Portal.canvas.HeaderCanvas |
28 | 34 | * @extends Neo.core.Base |
29 | 35 | * @singleton |
@@ -98,6 +104,8 @@ class HeaderCanvas extends Base { |
98 | 104 | */ |
99 | 105 | time = 0 |
100 | 106 | /** |
| 107 | + * Pre-allocated buffers for wave geometry. |
| 108 | + * Uses `Float32Array` to eliminate Garbage Collection pressure during the render loop. |
101 | 109 | * @member {Object} waveBuffers={bgA: null, bgB: null, fgA: null, fgB: null} |
102 | 110 | */ |
103 | 111 | waveBuffers = {bgA: null, bgB: null, fgA: null, fgB: null} |
@@ -218,11 +226,14 @@ class HeaderCanvas extends Base { |
218 | 226 |
|
219 | 227 | /** |
220 | 228 | * 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. |
222 | 233 | * |
223 | 234 | * @param {Number} width |
224 | 235 | * @param {Number} height |
225 | | - * @returns {Object} {shimmerA, shimmerB, count} |
| 236 | + * @returns {Object} {shimmerA, shimmerB, count} Metadata for rendering (scalars only) |
226 | 237 | */ |
227 | 238 | calculateStrandGeometry(width, height) { |
228 | 239 | let me = this; |
|
0 commit comments