Rhino3dm.js — Request for WASM64 (memory64) build to lift 2 GB heap limit

Hi,

I’m using rhino3dm.js (the JavaScript/WebAssembly build of openNURBS) in a browser-based 3D viewer to export large meshes to .3dm. I’m hitting the 32-bit WebAssembly linear memory ceiling (~2 GB addressable, ~4 GB hard cap) when serializing large models.

Concrete repro:

  • Input: ~28.6M vertices / 9.5M triangles across 54 meshes (single file → GLB ~670 MB on disk).
  • Payload handed to the worker: ~327 MB of Float32Array vertex positions (normals stripped, Rhino recomputes them).
  • Pipeline: meshes are pre-merged on the JS side, then for each group I call new rhino.Mesh(), mesh.vertices().add(…), mesh.faces().addFace(…), mesh.compact(), mesh.normals().computeNormals(), append to File3dm, then doc.toByteArray().
  • Result: after roughly 20–25 groups, verts.add() starts silently failing (vertex count stops incrementing), and the final doc.toByteArray() triggers Aborted(). Build with -sASSERTIONS for more info. — the classic Emscripten OOM abort when the WASM heap can’t grow further.
  • Tested on rhino3dm@8.4.0 and @7.15.0 , Chromium-based browser, dedicated Web Worker, INITIAL_MEMORY left at default and ALLOW_MEMORY_GROWTH implicitly on. Same outcome.

What I’d like to ask:

  1. Are there plans to publish a WASM64 / -sMEMORY64=1 build of rhino3dm.js so the linear memory can exceed the 4 GB cap on browsers that support the memory64 proposal (Chrome/Edge behind a flag today, shipping more broadly soon)?
  2. If not, would it be possible to expose a bulk/typed-array vertex and face ingestion API (e.g. mesh.vertices().setFromFloat32Array(buffer) / mesh.faces().setFromUint32Array(buffer)) to avoid the per-vertex/per-face JS↔WASM call overhead and the intermediate allocations that inflate heap usage?
  3. Any recommended EMSCRIPTEN_* build flags or Module instantiation options (e.g. higher INITIAL_MEMORY, MAXIMUM_MEMORY=4GB) you’d suggest in the meantime?

For now my workaround is to fall back to glTF/GLB export for models above ~15M vertices, but native .3dm output is what I actually want.

Happy to share more info if useful.

Thanks!

Hello!
Yes there are plans for WASM64, but I do not have a timeline for when it will be available.

@Holo The rhino3dm 8.32.1 release should include support for WASM64:

ESM (bundler / Node)

import rhino3dm from 'rhino3dm/wasm64/rhino3dm.module.js'

const rhino = await rhino3dm()
const sphere = new rhino.Sphere([0,0,0], 5)

CommonJS (Node)

const rhino3dm = require('rhino3dm/wasm64/rhino3dm.js')
rhino3dm().then(rhino => { /* ... */ })

Browser via CDN + import map

<script type="importmap">
{ "imports": {
    "rhino3dm": "https://cdn.jsdelivr.net/npm/rhino3dm@8.32.1/wasm64/rhino3dm.module.min.js"
}}
</script>
<script type="module">
  import rhino3dm from 'rhino3dm'
  const rhino = await rhino3dm()
</script>

WASM64 is now generally supported across Node and most major browsers. Unfortunately Safari still does not support wasm64, so I kept wasm32 as the default package. I might change this in a subsequent release of rhino3dm.js.

OK, after a lot of testing, iterating and bug tracking, with the help of AI, it appears there still is a 2GB limit on the WASM64. Here is the response I got:

Found it — and it’s conclusive. Answer is (a): a hard ceiling baked into the compiled .wasm.

Evidence 1 — the wasm memory section (decoded the binaries directly):

build declared max
rhino3dm@8.4.0 (wasm32) 2048 MB
rhino3dm@8.32.1 (wasm32) 2048 MB
rhino3dm@8.32.1/wasm64 2048 MB (flags 0x5 = memory64 + max present, 32768 pages)

The wasm64 build is 64-bit addressing but is still linked with MAXIMUM_MEMORY=2GB. memory.grow past that fails at the engine level — nothing on our side can lift it.

Evidence 2 — the glue confirms it. emscripten_resize_heap in the wasm64 module still has the wasm32 clamp verbatim:

if (!(2147483648 < requestedSize)) { ... wasmMemory.grow(...) ... Math.min(2147483648, ...) }
return false;

Any allocation request above 2 GiB returns false immediately, so malloc returns null.

Evidence 3 — why our probes were all -1/null. The minified module keeps HEAPU8/wasmMemory as closure locals; they are not exported on the Module object (_malloc is, but returned null — consistent with the growth failure path). So heapLen: -1 was our probe being blind, not a detached heap. Not (b), not evidence for (c).

What actually happens at 128 MB output: the archive writer’s buffer allocation crosses the 2 GB wall, malloc returns null, and rhino3dm’s toByteArray still reports the computed archive length — hence a correctly-sized, freshly-allocated (byteOffset: 0, bufLen === len, sameBuffer: false) but zero-filled array. It’s a silent OOM, not a stale view.

So there is no app-side workaround at this model size right now.

Thanks for the report. I forgot to set the maximum memory limit. I now set the max to 16GB for WASM64. Available on npm: https://www.npmjs.com/package/rhino3dm/v/8.32.2

Thank you! It now works and I was able to write out a 254MB Rhino file with meshes. Total memory use for the worker was 2.6GB. I will test it out on larger models too.

I really appreciate the work you put in and that you handled this so fast.