emscripten-core / emscripten-core/emscripten

Migrating library from Emscripten 1.38 to 2.x or 3.x causes significant performance degradation

Open
#18,517 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

I maintain the [h3-js](https://github.com/uber/h3-js) library, which uses Emscripten to transpile the [H3 core library](https://github.com/uber/h3) to a standalone Javascript package. Our current toolchain uses Emscripten 1.38, via the Docker container `trzeci/emscripten:sdk-tag-1.38.43-64bit` (now deprecated). We are using pure JS output, not WASM.

We would like to upgrade to the latest Emscripten version, and I tried this with a 2.x version but noticed performance degradation. I recently tried again with version 3.1.30, but saw the same issues. Some of the library's functions ran with comparable speed to the current version, but many, especially our core functions, saw a 10x slowdown (benchmarks below use Benchmark.js on Node 12):

**Emscripten 1.38.43**
```
latLngToCell x 458,094 ops/sec ±1.17% (90 runs sampled)
cellToLatLng x 1,200,561 ops/sec ±0.60% (87 runs sampled)
```
**Emscripten 3.1.30**
```
latLngToCell x 36,071 ops/sec ±0.61% (89 runs sampled)
cellToLatLng x 101,367 ops/sec ±1.29% (92 runs sampled)
```
Even when the library is converted to WASM, instead of JS, the slowdown is comparable. The functions in question are fairly mathematically intensive, using trig functions over 64-bit doubles.

Do you have any ideas or suggestions to fix the performance issue here? I'm hoping there's just a compilation flag I'm missing, but it's also possible that something changed in Emscripten that requires more attention. Thanks for your help.

Related discussion: https://github.com/uber/h3-js/issues/163

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.