Skip to content

wasmtime works extremely slow on kotlin benchmarks #13279

Closed

Description

@igoriakovlev

Using Wasmtime 44.0.1 we are having very slow benchmark execution.
The benchmark allocates and copies a lot of gc arrays and seems Wasmtime works inefficient with that (other engines, like v8, works much more faster).

To reproduce this one can use .wasm file and benchmark's config attached to this issue.

To run benchmark you need to execute the following cli command:

wasmtime -W gc,exceptions,function-references --dir=/ ./kotlin-wasm-benchmarks-wasmWasiBenchmark.wasm STUB $PWD/config 5 microBenchmarks.ArrayCopyBenchmark.copyInSameArray

To compare this with v8 you can run the following cli command:

node ./kotlin-wasm-benchmarks-wasmWasiBenchmark.mjs $PWD/config 5 microBenchmarks.ArrayCopyBenchmark.copyInSameArray

Here you can find the Kotlin source code for this benchmark.

Activity

  1. added
    wasm-proposal:gc
    on May 5, 2026
  2. fitzgen commented on May 5, 2026

    @fitzgen
    Member

    Thanks for filing an issue! It is expected that we won't be on-par with engines that have put hundreds more engineering years into the GCs than we have, but at the same time we shouldn't be multiple order of magnitude slower in general. Can you provide relative timings here? (That's generally a good bit of information to provide when filing performance-related issues).

    Probably much faster with the copying collector (-Ccollector=copying) but I don't think that has made it into a release yet, and only exists on main currently.

    In any case, I'll get around to taking a closer look soon ish.

  3. alexcrichton commented on May 5, 2026

    @alexcrichton
    Member

    @fitzgen FWIW I get, with node 24.15.0:

    $ node ./kotlin-wasm-benchmarks-wasmWasiBenchmark.mjs $PWD/config 5 microBenchmarks.ArrayCopyBenchmark.copyInSameArray
    (node:1050346) ExperimentalWarning: WASI is an experimental feature and might change at any time
    (Use `node --trace-warnings ...` to show where the warning was created)
    Warm-up #0: 435.285 ms/op
    Warm-up #1: 384.315 ms/op
    Warm-up #2: 585.851 ms/op
    Warm-up #3: 1,615.40 ms/op
    Warm-up #4: 2,232.04 ms/op
    Iteration #0: 1,664.03 ms/op
    Consumed blackhole value: -1805010299
    <RESULT>4744766272456097792</RESULT>
    

    and with current main:

    $ cargo run --release --  --dir / -Wgc,function-references,exceptions kotlin-wasm-benchmarks-wasmWasiBenchmark.wasm STUB $PWD/config 5 microBenchmarks.ArrayCopyBenchmark.copyInSameArray
    ...
    

    (never prints anything). I waited for ~1 minute where node fully completed in 8s.

    and with -Ccollector=copying

    $ cargo run --release -- -C collector=copying --dir / -Wgc,function-references,exceptions kotlin-wasm-benchmarks-wasmWasiBenchmark.wasm STUB $PWD/config 5 microBenchmarks.ArrayCopyBenchmark.copyInSameArray
        Finished `release` profile [optimized] target(s) in 0.11s
         Running `target/release/wasmtime -C collector=copying --dir / -Wgc,function-references,exceptions kotlin-wasm-benchmarks-wasmWasiBenchmark.wasm STUB /home/alex/code/wasmtime/config 5 microBenchmarks.ArrayCopyBenchmark.copyInSameArray`
    
    thread 'main' (1052828) panicked at crates/environ/src/gc.rs:507:32:
    invalid `VMGcKind`: 0b000000000000000000000000000000
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    

    (after a few seconds)


    Also, @igoriakovlev there's a typo in the node reproduction above which uses cissueopyInSameArray instead of copyInSameArray like in the Wasmtime snippet, and I'm assuming copyInSameArray is what's intended. I stay this because pasting the node command as-is completes instantaneously which looks like it's just not running anything.

  4. alexcrichton commented on May 5, 2026

    @alexcrichton
    Member

    A quick perf record of the drc collector shows that 70% of the time is in the array.copy libcall. That's known to be extremely slow in Wasmtime as it's lifting and lowering between high-level and VM types, so I suspect the lion's share of the improvement here is "optimize array.copy"

  5. alexcrichton commented on May 15, 2026

    @alexcrichton
    Member

    With the optimizations from #13382, plus the bug fixes in #13381, I've got the following results. The results in this table are total runtime for the entire wasm module to finish running. The module itself prints information and timing information but I'm not entirely sure what it is. I figure this is all indicative though:

    runtime time
    wasmtime gc=null 3.455
    wasmtime gc=drc 14.424
    wasmtime gc=copying 3.407
    node 6.984

    so, effectively, I believe that #13382 solves this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    wasm-proposal:gc

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions