Summary
Fix per-point wasm→JS call loop and listener leak in writeFP/writeFS JS library (js/jslibrary.js)
Environment
- Product/Service: FeatureSET-Display — Emscripten/wasm native layer + JS drawing
- Files:
emscripten/ARimageFsetDisplay.cpp:192-206, js/jslibrary.js
Problem Description
Two distinct bugs in the current design:
- Per-point wasm→JS call overhead:
readNFTMarker calls writeFP/writeFS in a per-point loop (ARimageFsetDisplay.cpp:200-206), so every feature point pays a separate wasm→JS crossing.
- Listener leak: Each
writeFP/writeFS call adds a new imageEv event listener that is never removed. Loading a marker with N feature points leaks N listeners. Loading a second marker doubles drawing work indefinitely.
Expected Behavior
- Feature points are accumulated in a native vector and transferred to JS in a single pass.
- The
imageEv listener is added once and reused; no accumulation across marker loads.
Actual Behavior
- N wasm→JS crossings per frame per marker.
- N event listeners leak per marker load, multiplying draw work each time a new marker is loaded.
Tasks
Impact
High — This is the highest-priority fix in the roadmap. The listener leak causes unbounded memory growth and multiplying draw cost on every marker load. Affects every other change that touches the drawing path.
Additional Context
This issue should be fixed before 1a (EM_ASM removal) since it affects the same drawing boundary.
Summary
Fix per-point wasm→JS call loop and listener leak in
writeFP/writeFSJS library (js/jslibrary.js)Environment
emscripten/ARimageFsetDisplay.cpp:192-206,js/jslibrary.jsProblem Description
Two distinct bugs in the current design:
readNFTMarkercallswriteFP/writeFSin a per-point loop (ARimageFsetDisplay.cpp:200-206), so every feature point pays a separate wasm→JS crossing.writeFP/writeFScall adds a newimageEvevent listener that is never removed. Loading a marker with N feature points leaks N listeners. Loading a second marker doubles drawing work indefinitely.Expected Behavior
imageEvlistener is added once and reused; no accumulation across marker loads.Actual Behavior
Tasks
nftPointsvector inARimageFsetDisplay.cpp(the loop at lines 192–198 is commented out — uncomment/fix it)writeFP/writeFSfromjs/jslibrary.jsand remove the--js-libraryflag if nothing else depends on itimageEvfiresImpact
High — This is the highest-priority fix in the roadmap. The listener leak causes unbounded memory growth and multiplying draw cost on every marker load. Affects every other change that touches the drawing path.
Additional Context
This issue should be fixed before 1a (EM_ASM removal) since it affects the same drawing boundary.