NFSU: reconciliation log
Full forensic audit and reconciliation changelog for nfsu.cc. Read the build overview first in How I put NFSU in a browser tab. Jump to: Changelog v2 — Mobile survival, WebGL 2 pooled tape & forensic pass (latest) · Changelog v1 — 1.47 GB gpu.js GC & WebGL 2 cache traps.
Changelog v2 · Mobile RAM, cold boot, WebGL 2 pooled tape & forensic reconciliation (latest)
Across commits 31c1167, 8cbf571, d6ef04c, e79e9d2, and the final forensic cleanup, we halved WASM memory, parallelized cold boot, closed car-streaming gaps, made GPU shaders lazy, capped an uncapped 375 fps loading-screen loop, replaced per-draw WebGL 2 closures with a pooled command tape, fixed the last native C build guard, and verified live Cloudflare R2 parity against local dist/ — without cutting a single song from the 2003 soundtrack.
wasm break dropped 1,548 → 585 MBhost/*.c pass native clang; 375 patches, 0 overlaps2.1 · Memory budget: halving WASM RAM before frame 1
Mobile Safari kills tabs once process footprint crosses ~1.5 GB. Previously, speed.wasm reserved a 2 GB fixed SharedArrayBuffer at boot, mapped 1 GB of flat guest address space, and allocated 16 MB stacks across 12 pthread workers — burning RAM before the title screen even drew.
| Allocation | Before | After | Source (file:line) |
|---|---|---|---|
| WASM linear memory | 2,048 MB | 1,024 MB | tools/recomp/build.py:183 (-sINITIAL_MEMORY=1024MB) |
| Guest address space | 1,024 MB | 384 MB | host/host.h:11 (GUEST_MEM=0x18000000u; measured use ~52 MB) |
| Thread stacks | 16 MB × 12 | 4 MB × 9 | tools/recomp/build.py:183, host/threads.c:285 (192 → 36 MB) |
| Boot worker pool | 12 workers | 9 workers | tools/recomp/build.py:184 + RN_NPRE=2 on mobile |
Live wasm break (Chrome) | 1,360–1,548 MB | 585 MB | Verified via webcheck.mjs --route (45 MB heap, 7 MB virtual) |
In plain termsImagine renting a 2-gigabyte warehouse to store 52 megabytes of boxes, when the landlord evicts anyone using more than 1.5 gigabytes. Shrinking the reservation to 1 GB and guest memory to 384 MB kept the exact same game and audio intact while cutting real WASM footprint by nearly a gigabyte.
2.2 · Cold boot, car chunks & immutable R2
- Parallel boot:
web/boot.jsdownloadspc/Speed.exein parallel with streamingout/speed.wasmcompilation viaPromise.all. - Car chunk coverage: Added 99 rows to
census/data_chunks.tsv(217 total).dist/data-chunks/now holds 454 gzipped pieces (273.40 MB from 505.2 MB source), reducing missed/Cars/Range 206s in the cold trace to 0. - Mobile throttling & CDN: Cached the overlay
HEADresponse inhost/trackfiles.c:63-66; phones passRN_NPRE=2(host/files.c:313-318) and cap rival prefetch to 5 cars (host/rivals.c:58-60).tools/upload_r2.shgzipsSpeed.exeand setsCache-Control: public, max-age=31536000, immutableondata-chunks/,game/, andpc/Speed.exe.
2.3 · Mobile GPU: lazy shaders & 540p WebGL 2 cap
| Track | Files | Change & verified effect |
|---|---|---|
| Lazy shaders | web/gpu.js | Moved 6 optional shader/pipeline groups (FXAA, CAS, Bloom, PS, Skinning, Mipmap) behind lazy getters. Boot shaderModules 7 → 1 (clearShader only), renderPipelines 7 → 0. |
| WebGL 2 mobile cap | web/mode.js, web/boot.js | On mobile + WebGL 2 fallback, defaults CAS sharpening to off (unless ?sharp= is explicitly passed) and caps backbuffer from 1280×720 → 960×540 (44% fewer pixels). |
| DXT1/3/5 audit | host/d3d9.c:1536-1618 | CPU-decoded to RGBA8 in decode_texels(); native BCn is not viable on mobile WebGL 2 (ASTC/ETC2 chips). Safe 512 px hook documented in upload_level() skipping 1,135 HUD/FE keys. |
2.4 · Safari/WebKit Race Footprint Gate (WebGPU & WebGL 2)
Two WebGL 2 root causes were caught and eliminated back-to-back: (1) an uncapped ~375 fps loading-screen loop in PC_Loading.fng fixed by a universal 60 fps ceiling in host/d3d9.c:787-814 (d6ef04c), and (2) ~66k/s per-draw closures and .slice()/.map() copies in web/webgpu_gl.js replaced by a pooled flat command tape and reusable per-device replay state (e79e9d2; glcheck 13/13 original, 17/17 remaster).
Run (Playwright WebKit + footprint -p) | Race HUD | Menus | Race footprint | Stability | Result |
|---|---|---|---|---|---|
| Baseline WebGPU (before) | reached | 855 MB | 6,000 MB @ 88 s | killed by OS | FAIL |
| Baseline WebGL 2 (before) | reached | 970–1,800 MB | 9,000 MB | killed by OS | FAIL |
WebGPU (8cbf571) | 25.9 s | 599–612 MB | 1,006 MB @ 91 s | 0 HUNG, 0 STOP | PASS ≤ 1.5 GB |
| WebGL 2 before pacer fix | never reached | ~1,200 MB | 5,538 MB @ 66 s | 7 HUNG, killed | FAIL (375 fps) |
WebGL 2 after pacer fix (d6ef04c) | 29.15 s | 653–1,439 MB | 2,009 → 4,032 MB @ 91 s | 0 HUNG, 0 STOP | Fixed load crash |
WebGL 2 + pooled tape (e79e9d2) | 27.70 s | 656–717 MB | 1,078 → 1,513 MB @ 90 s (-62.5%) | 0 HUNG, 0 STOP, 30.0 fps | PASS (~1.5 GB) |
In plain termsFirst, the loading screen was painting a static progress bar 375 times per second and drowning Safari before the race even started. Then, during racing, the WebGL 2 wrapper created two tiny JavaScript functions and three temporary arrays on every single draw call — 66,000 times a second. Replacing those with a reusable flat tape cut 90-second WebGL 2 memory from 4.03 GB down to 1.51 GB at a locked 30 fps.
2.5 · Final forensic reconciliation (5-layer check)
| Layer | Audit result | Action taken |
|---|---|---|
C Host (host/*.c) | host/files.c:406-410 (track_drop()) sat outside #ifdef __EMSCRIPTEN__, breaking native clang | Guarded track_drop() under #ifdef __EMSCRIPTEN__; now 28/28 host/*.c pass native clang -fsyntax-only |
| Binary & Lifter | Speed.exe MD5 b6b9232c55376b3c38c56aac1f8a121d verified; 13,764 lifted functions (0 failed); 375 active patches, 0 overlaps | Verified clean |
Web JS (web/*.js) | 20/20 scripts pass syntax check; glcheck 13/13 original & 17/17 remaster | Verified clean |
dist/ vs Live R2 | dist/manifest.json = 5,677 files / 2,100.33 MB (1.956 GiB); live nfsu.cc byte-for-byte MATCH on boot.js, gpu.js, webgpu_gl.js, mode.js, data-chunks.json | Reconciled stale 5,589 count in plan.json step 2 row 3 |
| Git & Worktrees | 3 dead prunable worktrees left from retired UG2 slices | Ran git worktree prune; active branches kept untouched |
Changelog v1 · 1.47 GB gpu.js GC churn, WebGL 2 cache traps & dead mc.c hook
Earlier forensic audit after retiring the UG2 world mode and shipping the initial WebGL 2 fallback (57c6aee):
web/gpu.jsweb/webgpu_gl.jshost/mc.c & cave 0x797600plan.json string boolean, orphaned HANDOFF.md SHAs & manifest count fixed1.1 · web/gpu.js — 1.47 GB of per-draw GC churn
An iPhone XR froze on the live site. WebKit malloc_history attributed 5.4 GB of the process footprint to the JS heap (JSC/bmalloc). Chrome's sampling heap profiler over 12 seconds of racing (logs/ch_hp3.heap.json) captured 2,112.9 MB of short-lived JS allocations; 69.7% (1,472.2 MB) came from runList (968.9 MB), pipeline (280.9 MB), and sampler (222.4 MB).
// web/gpu.js — before: allocated on every GPU_DRAW (hundreds per frame)
const key = [g(D_VS), g(D_PS), g(D_DECL), stride, g(D_TOPO), ds, ...].join(',');
pass.setBindGroup(0, uBind, [uoff]);
const entries = []; // built with 3 objects per texture even on cache hit
// after: zero-alloc Map tries, packed 28-bit sampler key, hoisted tuples
const pl = pipeline(w, a, stride, rt.sc || 1); // vs._pipes → ps → decl → entry[] + tag
UOFF_ARR[0] = uoff; pass.setBindGroup(0, uBind, UOFF_ARR);
let bg = findTexBind(ps.texMask, w, a); // entries[] allocated only on miss
Reconciled. samplerFrom(w, to) packs all six sampler fields into one 28-bit integer key; pipeline() uses a nested Map trie with an integer fast-reject tag; runList tracks pass targets, viewports and scissors as scalars and hoists UOFF_ARR and BF_ARR.
1.2 · web/webgpu_gl.js — four state-cache traps
| Site | Failure mode | Fix |
|---|---|---|
skipSameState | Cached GL enables, blend state and bindings persisted after GPU context loss | Added gl._resetSameState() hooked to webglcontextlost and webglcontextrestored |
colorSamplerFor | Cached on samp._rnColor with no device scope or descriptor validation | Moved to a WeakMap on device._colorSamplerBySamp verifying all 6 sampler fields |
texBinding | Keyed by index * 4096 + binding; collides whenever binding >= 4096 | Replaced with a nested Map (index → binding) scoped by program link version |
uloc | Cached WebGLUniformLocations survived gl.linkProgram | Wrapped gl.linkProgram to clear p._ul and increment p._linkVer |
1.3 · host/mc.c & state drift
Reconciled. Retired the dead pedestrian detour at Speed.exe:0x4479be / cave 0x797600 (host/mc.c, host/mc.h, tools/recomp/patches_mc.py moved to attic/mc/; active patches 377 → 375). Fixed "done": "False" string boolean in plan.json row 11 and orphaned pre-rewrite SHAs in HANDOFF.md.
Links: repo · How I put NFSU in a browser tab · nfsu.cc
Auditoría forense completa y changelog de reconciliaciones de nfsu.cc. Lee primero la historia general en Cómo metí NFSU en una pestaña del navegador. Ir directo a: Changelog v2 — Supervivencia móvil, cinta pooled en WebGL 2 y pasada forense (más reciente) · Changelog v1 — 1.47 GB de GC en gpu.js y trampas de caché en WebGL 2.
Changelog v2 · RAM móvil, arranque rápido, cinta pooled en WebGL 2 y reconciliación forense (más reciente)
A lo largo de los commits 31c1167, 8cbf571, d6ef04c, e79e9d2 y la limpieza forense final, partimos a la mitad la memoria WASM, paralizamos el arranque en frío, cerramos huecos de streaming de autos, volvimos perezosos los shaders de GPU, pusimos techo a un ciclo sin freno de 375 fps en la pantalla de carga, reemplazamos los closures por draw en WebGL 2 por una cinta plana reutilizable, cerramos el último guard nativo en C y verificamos paridad byte a byte contra Cloudflare R2 — sin quitar ni una canción del soundtrack de 2003.
wasm break real bajó 1,548 → 585 MBhost/*.c pasan clang nativo; 375 parches, 0 traslapes2.1 · Presupuesto de memoria: partir a la mitad la RAM WASM antes del cuadro 1
Safari en iOS mata la pestaña cerca de 1.5 GB de huella. Antes, speed.wasm reservaba un SharedArrayBuffer fijo de 2 GB al arrancar, mapeaba 1 GB de espacio plano para el juego y daba stacks de 16 MB a 12 workers — quemando RAM antes de dibujar siquiera la pantalla de título.
| Reserva | Antes | Después | Evidencia (archivo:línea) |
|---|---|---|---|
| Memoria lineal WASM | 2,048 MB | 1,024 MB | tools/recomp/build.py:183 (-sINITIAL_MEMORY=1024MB) |
| Espacio plano guest | 1,024 MB | 384 MB | host/host.h:11 (GUEST_MEM=0x18000000u; uso real ~52 MB) |
| Stacks de hilos | 16 MB × 12 | 4 MB × 9 | tools/recomp/build.py:183, host/threads.c:285 (192 → 36 MB) |
| Pool de workers al boot | 12 workers | 9 workers | tools/recomp/build.py:184 + RN_NPRE=2 en celular |
wasm break real (Chrome) | 1,360–1,548 MB | 585 MB | Verificado con webcheck.mjs --route (45 MB heap, 7 MB virtual) |
En simpleImagina rentar una bodega de 2 gigabytes para guardar 52 megabytes de cajas, cuando el casero desaloja a cualquiera que ocupe más de 1.5 gigabytes. Bajar la reserva a 1 GB y el espacio del juego a 384 MB dejó intactos el juego y toda su música, recortando casi un gigabyte real de huella WASM.
2.2 · Arranque en frío, chunks de autos y R2 inmutable
- Arranque en paralelo:
web/boot.jsdescargapc/Speed.exeen paralelo con la compilación streaming deout/speed.wasmmediantePromise.all. - Cobertura de chunks de autos: Se agregaron 99 filas a
census/data_chunks.tsv(217 en total).dist/data-chunks/ahora guarda 454 piezas gzip (273.40 MB desde 505.2 MB originales), bajando a 0 los Range 206 crudos de/Cars/en la traza en frío. - Control móvil y CDN: Se cacheó el
HEADde overlay enhost/trackfiles.c:63-66; en celular se pasaRN_NPRE=2(host/files.c:313-318) y se limita el prefetch de rivales a 5 autos (host/rivals.c:58-60).tools/upload_r2.shsubeSpeed.execomprimido con gzip y marcaCache-Control: public, max-age=31536000, immutableendata-chunks/,game/ypc/Speed.exe.
2.3 · GPU móvil: shaders perezosos y tope 540p en WebGL 2
| Frente | Archivos | Cambio y efecto verificado |
|---|---|---|
| Shaders perezosos | web/gpu.js | Se movieron 6 grupos opcionales (FXAA, CAS, Bloom, PS, Skinning, Mipmap) a getters bajo demanda. Al arrancar startGpu(): shaderModules 7 → 1 (solo clearShader), renderPipelines 7 → 0. |
| Tope WebGL 2 móvil | web/mode.js, web/boot.js | En móvil con respaldo WebGL 2, CAS arranca en off (salvo ?sharp= explícito) y el backbuffer baja de 1280×720 → 960×540 (44% menos píxeles). |
| Auditoría DXT1/3/5 | host/d3d9.c:1536-1618 | Decodificado en CPU a RGBA8 en decode_texels(); BCn nativo no es viable en WebGL 2 móvil (chips ASTC/ETC2). Punto seguro de tope 512 px documentado en upload_level() saltando 1,135 llaves HUD/FE. |
2.4 · Gate real en Safari/WebKit (WebGPU y WebGL 2)
Se atraparon y cerraron dos causas raíz consecutivas en WebGL 2: (1) un ciclo sin freno de ~375 fps en PC_Loading.fng corregido con un techo universal de 60 fps en host/d3d9.c:787-814 (d6ef04c), y (2) ~66k/s closures por draw y copias .slice()/.map() en web/webgpu_gl.js reemplazados por una cinta plana reutilizable de comandos y estado de replay por device (e79e9d2; glcheck 13/13 original, 17/17 remaster).
Corrida (Playwright WebKit + footprint -p) | HUD carrera | Menús | Huella carrera | Estabilidad | Resultado |
|---|---|---|---|---|---|
| Baseline WebGPU (antes) | llegó | 855 MB | 6,000 MB @ 88 s | matado por el OS | FAIL |
| Baseline WebGL 2 (antes) | llegó | 970–1,800 MB | 9,000 MB | matado por el OS | FAIL |
WebGPU (8cbf571) | 25.9 s | 599–612 MB | 1,006 MB @ 91 s | 0 HUNG, 0 STOP | PASS ≤ 1.5 GB |
| WebGL 2 antes del pacer | no llegó | ~1,200 MB | 5,538 MB @ 66 s | 7 HUNG, matado | FAIL (375 fps) |
WebGL 2 tras arreglo pacer (d6ef04c) | 29.15 s | 653–1,439 MB | 2,009 → 4,032 MB @ 91 s | 0 HUNG, 0 STOP | Carga arreglada |
WebGL 2 + cinta pooled (e79e9d2) | 27.70 s | 656–717 MB | 1,078 → 1,513 MB @ 90 s (-62.5%) | 0 HUNG, 0 STOP, 30.0 fps | PASS (~1.5 GB) |
En simplePrimero, la pantalla de carga pintaba una barra estática 375 veces por segundo y ahogaba a Safari antes de arrancar la carrera. Luego, al manejar, el traductor WebGL 2 creaba dos funciones nuevas y tres arreglos temporales en cada draw — 66,000 veces por segundo. Cambiarlo a una cinta plana reutilizable bajó la memoria en WebGL 2 a los 90 s de 4.03 GB a 1.51 GB corriendo parejo a 30 fps.
2.5 · Reconciliación forense final (auditoría en 5 capas)
| Capa | Hallazgo forense | Acción aplicada |
|---|---|---|
Host C (host/*.c) | host/files.c:406-410 (track_drop()) estaba fuera de #ifdef __EMSCRIPTEN__ y rompía clang nativo | Protegido bajo #ifdef __EMSCRIPTEN__; ahora 28/28 host/*.c pasan clang -fsyntax-only nativo |
| Binario y Lifter | MD5 de Speed.exe b6b9232c55376b3c38c56aac1f8a121d verificado; 13,764 funciones (0 fallidas); 375 parches, 0 traslapes | Verificado limpio |
Web JS (web/*.js) | 20/20 scripts pasan sintaxis; glcheck 13/13 original y 17/17 remaster | Verificado limpio |
dist/ vs R2 en vivo | dist/manifest.json = 5,677 archivos / 2,100.33 MB (1.956 GiB); paridad byte a byte en nfsu.cc para boot.js, gpu.js, webgpu_gl.js, mode.js, data-chunks.json | Reconciliado el conteo desfasado 5,589 en plan.json fila 3 |
| Git y Worktrees | 3 worktrees muertos (prunable) de ramas UG2 retiradas | Ejecutado git worktree prune; ramas activas intactas |
Changelog v1 · 1.47 GB de GC en gpu.js, trampas de caché en WebGL 2 y retiro de mc.c
Auditoría forense anterior tras retirar el modo mundo de UG2 y lanzar el respaldo inicial en WebGL 2 (57c6aee):
web/gpu.jsweb/webgpu_gl.jshost/mc.c y la cueva 0x797600plan.json, SHAs huérfanos en HANDOFF.md y conteo de manifiesto1.1 · web/gpu.js — 1.47 GB de presión al GC por cuadro
Un iPhone XR se congeló en el sitio en vivo. malloc_history de WebKit atribuyó 5.4 GB de la huella del proceso al heap de JS (JSC/bmalloc). El perfilador de heap de Chrome durante 12 segundos de carrera (logs/ch_hp3.heap.json) capturó 2,112.9 MB de asignaciones temporales; el 69.7% (1,472.2 MB) salía de runList (968.9 MB), pipeline (280.9 MB) y sampler (222.4 MB).
// web/gpu.js — antes: asignado en cada GPU_DRAW (cientos por cuadro)
const key = [g(D_VS), g(D_PS), g(D_DECL), stride, g(D_TOPO), ds, ...].join(',');
pass.setBindGroup(0, uBind, [uoff]);
const entries = []; // 3 objetos por textura incluso cuando ya estaba en caché
// después: tries de Map sin asignaciones, clave entera de 28 bits, tuplas reusadas
const pl = pipeline(w, a, stride, rt.sc || 1); // vs._pipes → ps → decl → entry[] + tag
UOFF_ARR[0] = uoff; pass.setBindGroup(0, uBind, UOFF_ARR);
let bg = findTexBind(ps.texMask, w, a); // entries[] solo si hay miss
Reconciliado. samplerFrom(w, to) empaqueta los seis campos del sampler en un entero de 28 bits; pipeline() usa un trie de Maps con tag entero de descarte rápido; runList rastrea targets, viewports y scissors como escalares y reutiliza UOFF_ARR y BF_ARR.
1.2 · web/webgpu_gl.js — cuatro trampas de caché de estado
| Sitio | Modo de fallo | Arreglo |
|---|---|---|
skipSameState | Estados GL, blend y bindings en caché sobrevivían a una pérdida de contexto | Se agregó gl._resetSameState() conectado a webglcontextlost y webglcontextrestored |
colorSamplerFor | Guardado directo en samp._rnColor sin aislar por dispositivo ni validar descriptor | Movido a un WeakMap en device._colorSamplerBySamp verificando los 6 campos |
texBinding | Clave index * 4096 + binding; colisiona si binding >= 4096 | Reemplazado por un Map anidado (index → binding) acotado por versión de link |
uloc | WebGLUniformLocations en caché sobrevivían a gl.linkProgram | Se envolvió gl.linkProgram para limpiar p._ul e incrementar p._linkVer |
1.3 · host/mc.c y desfase de estado
Reconciliado. Se retiró el desvío peatonal muerto en Speed.exe:0x4479be / cueva 0x797600 (host/mc.c, host/mc.h y tools/recomp/patches_mc.py movidos a attic/mc/; parches activos 377 → 375). Se corrigió el booleano string "done": "False" en la fila 11 de plan.json y los SHAs huérfanos en HANDOFF.md.
Enlaces: repo · Cómo metí NFSU en una pestaña del navegador · nfsu.cc