Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[perf] wasm is not using resizable array buffer #4416

Open
loynoir opened this issue Jan 27, 2025 · 0 comments
Open

[perf] wasm is not using resizable array buffer #4416

loynoir opened this issue Jan 27, 2025 · 0 comments
Labels

Comments

@loynoir
Copy link

loynoir commented Jan 27, 2025

Describe the Bug

[perf] wasm is not using resizable array buffer.

Steps to Reproduce

use wasm_bindgen::prelude::wasm_bindgen;

#[wasm_bindgen]
pub fn hello() -> Vec<u8> {
    vec![0u8; 42]
}

Import generated wasm module and inspect wasm memory.

Find wasm is not using resizable array buffer.

> mod.__wasm.memory.buffer.resizable
false
> mod.__wasm.memory.buffer.byteLength 
1114112
> void (ab0 = mod.__wasm.memory.buffer)
undefined

Call small allocation related fn first time.

ArrayBuffer is NOT same object.

> void mod.hello()
undefined
> mod.__wasm.memory.buffer.byteLength 
1179648
> void (ab1 = mod.__wasm.memory.buffer)
undefined
> ab1 === ab0
false

Call small allocation related fn second time.

ArrayBuffer is same object.

> void mod.hello()
undefined
> mod.__wasm.memory.buffer.byteLength 
1179648
> void (ab2 = mod.__wasm.memory.buffer)
undefined
> ab2 === ab1
true
> 1179648 - 1114112
65536

Expected Behavior

When actual allocation, wasm memory buffer is same ArrayBuffer .

Actual Behavior

When actual allocation, wasm memory buffer is NOT same ArrayBuffer .

Not sure it is done by COPY or not.

Additional Context

Not sure ab0 is COPY to ab1 or not.

Should have benchmark comparing with using resizable array buffer as wasm memory buffer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant