Skip to content

[1b] Fix writeFP/writeFS per-point wasm→JS call loop and listener leak #18

Description

@kalwalt

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:

  1. 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.
  2. 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

  • Populate the already-declared nftPoints vector in ARimageFsetDisplay.cpp (the loop at lines 192–198 is commented out — uncomment/fix it)
  • Expose feature-set points the same way (new vector field on the returned struct)
  • Delete writeFP / writeFS from js/jslibrary.js and remove the --js-library flag if nothing else depends on it
  • Have JS draw all points in a single pass after imageEv fires

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions