Description
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 JsValue
s 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
- Install wasm-pack with reference type support using this branch (remember to switch branches) using cargo install while in the directory
- Clone this minimal reproduction repo, `
- run
wasm-pack build --release --ref-types --target web
to build - 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
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.
Sorry if this has already been reported.