alanross / AlvaAR

World tracking for WebAR. A Javascript library for Augmented Reality to run SLAM in the browser.
GNU General Public License v3.0
349 stars 73 forks source link

simd and threads are both supported by Mobile Safari, enable streaming instantiation #23

Open doctorpangloss opened 9 months ago

doctorpangloss commented 9 months ago

This middleware will add the appropriate CORS headers to enable WASM multithreading:

import { NextFunction, Request, Response } from "express";

export function corsHeaders(req: Request, res: Response, next: NextFunction) {
  res.header("Cross-Origin-Opener-Policy", "same-origin");
  res.header("Cross-Origin-Embedder-Policy", "require-corp");
  next();
}

Naturally, this must be on https.

Additionally, you may consider building EIGEN with ARM NEON SIMD.

iOS 16.5.1 is the minimum version for working SIMD, although 16.4 will report it is supported. See https://github.com/microsoft/onnxruntime/issues/15644 https://webkit.org/blog/14154/webkit-features-in-safari-16-5/#:~:text=Fixed%20WASM%20SIMD%20breaking%20WebP%20decoding%20applications

wasm-feature-detect can detect threads and SIMD before loading the appropriate build.

alanross commented 9 months ago

Thank you for including this code snippet @doctorpangloss. While the update will enable support for the specific mobile browser, it's important to note that WASM multithreading still faces limited support across various versions, platforms, and browsers. Additionally, this change will require you running your own server to deploy your project. I'm looking forward to the day multithreading is better supported, as it would enhance the robustness and performance of the library.