Skip to content

Adding JsValues to Vec<JsValue> takes quadratic time with reference types enabled for first run. #2291

Closed
@richardlett

Description

@richardlett

Describe the Bug

I wanted to try out reference types. In testing, it sped up my code, except on first run, where it is slowed it down dramatically. It appears to take quadratic time with respect to number of items added.

I've isolated it to adding items to a vec.

Addin 1.2 million JsValues to a vec, using reference types made the first run go from .2-.3 seconds (not using them) to ~150 seconds.

(the JsValue was always 1)

Subsequent runs after removing all items were faster than the first. (Only <0.7 seconds for 1.2 million)

Removing all items from first, and then re-adding 1 million items to a second object was also faster.

Steps to Reproduce

  1. Install wasm-pack with reference type support using this branch (remember to switch branches) using cargo install while in the directory
  2. Clone this minimal reproduction repo, `
  3. run wasm-pack build --release --ref-types --target web to build
  4. Create a static http server at root, using python3 -m http.server or similar, and open in firefox. After a while, in the console you will see
    image

wasm-push is 1.2 million items to a vec. wasm-pop is removing them all. Wasm-pushpop does both.

Expected behavior:

Take linear time to add N items to a vec.

Actual behavior:

It seems to take quadratic time. Here's a table of time taken for first N items added vs a chart.

image

Sorry if this has already been reported.

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