Skip to content

whether there are plans for the API to support JavaScript/WebAssembly (WASM)? #254

@JiesenSun

Description

@JiesenSun

Abstract

This issue proposes adding support for JavaScript/WebAssembly (WASM) usage to the existing API, enabling the library to be executed directly in web and other WASM-capable environments without requiring a native runtime.

Motivation

What problem is it trying to solve?

Currently, the API can only be used in native environments (e.g., C++/Python). This limits its adoption in modern web-based applications, such as browser-based simulations, interactive visualization tools, and educational platforms that rely on JavaScript and WASM.

Who is affected by the change?
• Web developers who want to integrate the engine into browser-based applications
• Users building interactive or educational tools (e.g., online labs, visualization dashboards)
• Developers targeting cross-platform deployment where native binaries are difficult to distribute

Why is this a good solution?

WebAssembly provides near-native performance while running securely in browsers and other sandboxed environments. Adding JS/WASM support would significantly lower the barrier to entry, broaden the user base, and enable new application scenarios such as client-side simulations and real-time interactive demos.

Possible Solutions

Proposed Approach
• Compile the core library to WebAssembly using Emscripten
• Expose a JavaScript-friendly API (JS glue layer) that wraps the existing C/C++ interfaces
• Provide a minimal, stable JS API surface for common use cases (e.g., initialization, computation, querying results)

Alternative Solutions Considered
1. Server-side execution only (REST API)
• Pros: Simpler implementation
• Cons: Higher latency, server cost, no offline usage
2. Pure JavaScript reimplementation
• Pros: Native JS integration
• Cons: High maintenance cost, risk of numerical inconsistency, lower performance

The WASM-based approach is preferred because it preserves the existing, well-tested core logic while enabling efficient and portable execution in JavaScript environments.

References
• Related discussions on WebAssembly support
• Existing Emscripten-based builds or experiments
• Similar projects providing WASM bindings (e.g., scientific or numerical libraries)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions