Skip to content

[1a] Replace EM_ASM_ block in ARimageFsetDisplay.cpp with embind #17

@kalwalt

Description

@kalwalt

Summary

Replace EM_ASM_ block in emscripten/ARimageFsetDisplay.cpp (lines 180–190) with idiomatic C++ / embind

Environment

  • Product/Service: FeatureSET-Display — Emscripten/wasm native layer
  • File: emscripten/ARimageFsetDisplay.cpp lines 180–190, emscripten/bindings.cpp lines 46–55

Problem Description

The current block uses EM_ASM_ to write frameIbwpointer, frameimgBWsize, and frameFeaturePoints onto a JS-side arfset.frameMalloc object. This incurs an extra wasm→JS crossing on every frame and introduces hidden global state. The same three values are already exposed through the embind nftMarker value_object (pointer, imgBWsize, nftFeaturePoints in bindings.cpp:46-55), so JS can read them directly from the returned struct.

Expected Behavior

No EM_ASM_ blocks remain in the hot path. JS reads pointer, imgBWsize, and nftFeaturePoints directly from the nftMarker struct returned by embind, eliminating the side-channel global.

Actual Behavior

EM_ASM_ fires every frame, crossing the wasm↔JS boundary and mutating arfset.frameMalloc as a hidden side-channel.

Tasks

  • Pick approach (recommended: drop EM_ASM_ and read from nftMarker)
  • Remove the EM_ASM_ block from ARimageFsetDisplay.cpp:180-190
  • Update JS callers in js/arfset.api.js and src/ARFset.js to read from the returned nftMarker struct instead of arfset.frameMalloc

Impact

Medium — Performance: eliminates a per-frame wasm→JS crossing and removes hidden global state. No functional regression expected.

Additional Context

If a JS-visible global is genuinely required, prefer emscripten::val (pure C++, type-safe):

val::global("arfset")["frameMalloc"].set("frameIbwpointer", arc->imgBW);

Last resort: EM_JS(void, set_frame_malloc, (...), { ... }) — parsed once at build time.

See also: issue 1b (listener leak fix) should land first as it touches the same drawing path.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions