Skip to content
This repository was archived by the owner on Oct 24, 2023. It is now read-only.
This repository was archived by the owner on Oct 24, 2023. It is now read-only.

Should implementations or hosts be allowed to observably round up byteLength? #24

Closed

Description

@syg

Like #23, but for byteLength.

Should the following be allowed?

let rab = new ResizableArrayBuffer(2000, 8192);
console.log(rab.byteLength); // 4096
rab.resize(5000);
console.log(rab.byteLength); // 8192

Pros:

  • Alignment with something like WebAssembly, which only accepts linear memory sizes in multiples of its hardcoded page size. (WebAssembly's page size is 65,536, which I think is too large to use for general-purpose buffers like this in JS.)

Cons:

Unlike #23, I think the cons more clearly outweigh the pros here and we shouldn't make this change.

Activity

  1. codehag commented on Jan 27, 2021

    @codehag
  2. lars-t-hansen commented on Jan 27, 2021

    @lars-t-hansen

    And in the future, WebAssembly may have multiple notions of page size (smaller / custom page sizes are a common request, since so many computations are expressed in terms of the page size).

    On some ARM64 devices / OSs, pages are 16KB (ARM64 Linux typically, though I see both Android and macOS are reverting to 4K, or allowing that to happen at least). So even if the rounding algorithm is not implementation-specific, it may be hardware-specific. I don't know if fingerprinting is still a real concern, but this would add a bit or two to that.

  3. bmeck commented on Jan 27, 2021

    @bmeck
    Member

    moved from #23

    I would note APIs that consume TypedArrays may have surprising behavior to programmers if things are resized:

    const meta = new ResizableArrayBuffer(22); // archive file metadata for example, may grow as entries grow
    // ...
    write(new Uint8Array(meta)); // wrote 1024 or some such bytes instead? now archive is misaligned
  4. bmeck commented on Jan 27, 2021

    @bmeck
    Member

    Are there any concerns with a potential loop of a recursive compaction failing?

    while (arrBuff.byteLength > usedBytes) {
      usedBytes = compactData();
      arrBuff.resize(usedBytes);
    }
  5. syg commented on Jan 27, 2021

    @syg
    CollaboratorAuthor

    Are there any concerns with a potential loop of a recursive compaction failing?

    Another interesting use case, yeah. I'm more and more convinced having the implementation rounding the requested resize size or the constructor size is just too surprising, and we shouldn't do it.

  6. syg commented on Feb 22, 2021

    @syg
    CollaboratorAuthor

    I haven't heard any compelling use cases beyond implementation ease to allow byteLength to be observably rounded. I find @bmeck's examples compelling, so I'm closing this issue with the decision to not allow implementations to observably round byteLength.

  7. codehag commented on Mar 10, 2021

    @codehag

    I mentioned this in our call on Friday, repeating it here: We would be more comfortable if this wasn't implementation defined, and would propose going with rounding up to 64k like Wasm.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions