Skip to content

[threads][js-api] Preserve SharedArrayBuffer identity on grow(0)#255

Open
backes wants to merge 1 commit intoWebAssembly:mainfrom
backes:shared-memory-no-refresh-on-grow-0
Open

[threads][js-api] Preserve SharedArrayBuffer identity on grow(0)#255
backes wants to merge 1 commit intoWebAssembly:mainfrom
backes:shared-memory-no-refresh-on-grow-0

Conversation

@backes
Copy link
Copy Markdown
Member

@backes backes commented Apr 23, 2026

Update the JS-API spec to ensure that growing a shared memory by 0 pages does not recreate the SharedArrayBuffer object. This aligns with the Threads proposal overview and allows JS to check if growth actually occurred by comparing object identity.

The spec'ed behavior now matches the implementation in all major browsers, as discussed in #248.

  • In "refresh the Memory buffer", return early if a shared memory's size hasn't changed.
  • Defer refreshing the buffer for shared memories until the "buffer" property or "toFixedLengthBuffer()" is accessed. This is a non-observable performance optimization that also ensures remote growth is picked up.
  • Maintain immediate refresh for unshared memories to ensure detachment.
  • Add explanatory notes and fix a minor typo.

See #248.

Update the JS-API spec to ensure that growing a shared memory by 0 pages
does not recreate the SharedArrayBuffer object. This aligns with the
Threads proposal overview and allows JS to check if growth actually
occurred by comparing object identity.

The spec'ed behavior now matches the implementation in all major
browsers, as discussed in WebAssembly#248.

- In "refresh the Memory buffer", return early if a shared memory's size
  hasn't changed.
- Defer refreshing the buffer for shared memories until the "buffer"
  property or "toFixedLengthBuffer()" is accessed. This is a non-observable
  performance optimization that also ensures remote growth is picked up.
- Maintain immediate refresh for unshared memories to ensure detachment.
- Add explanatory notes and fix a minor typo.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant