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

Deeply immutable binary data #134

Closed
Gozala opened this issue Jun 23, 2020 · 5 comments
Closed

Deeply immutable binary data #134

Gozala opened this issue Jun 23, 2020 · 5 comments

Comments

@Gozala
Copy link

Gozala commented Jun 23, 2020

Today only binary data (other then Blob) is mutable and only way to efficiently share it across threads imposes transferring underlying ArrayBuffer in which case it becomes detached on the sender thread.

It would be really great to consider immutable binary data as part of this effort, which would make it possible to share data (efficiently) across threads without having to copy or transfer it.

@littledan
Copy link
Member

As an initial pass, BigInt can hold binary data, and it's also a primitive. I'd be interested in exploring primitive types for other things too, but it would be best in the context of understanding for which cases BigInt falls short.

@Gozala
Copy link
Author

Gozala commented Jul 7, 2020

@littledan I think we might be talking past each other here. I'll try to elaborate on specific use case I had in mind. https://ipfs.io/ uses cryptographic content identifiers (CID) to address content in the network (spec, js implementation).

As name implies it's identifier derived from content (hash) so by definition it's immutable, also being identifier it is used all over the place and handful of utility functions e.g. toString() are implemented that do caching to avoid unnecessary computations. However as I've alluded to in original comment there is no good way to represent such CIDs in JS because:

  1. ArrayBuffer aren't immutable, even though CID make use of them as "immutable by agreement". That means they can get corrupt if underlying data is mutated (intentionally or not).
  2. As we attempt to push things off to worker thread we're finding that "immutable by agreement" is really fragile, because if ArrayBuffer is transferred any "immutable by agreement" data structures (like CIDs) get corrupt as buffer gets cleared on the main thread.
    • This can often happen by accident when larger buffer is allocated and different "immutable by agreement" structures point to range with-in it. Some temporary structures may appear good candidates for transfer, as shared buffer with other structures is overlooked.

Have some form of immutable shared array buffer could address outlined problems in systems like ipfs, or many other distributed / p2p systems for that matter.

@littledan
Copy link
Member

Thanks, it's helpful to have these concrete use cases to understand better. Could you elaborate on what makes BigInt not a suitable way to represent binary data? This would help me understand what is needed.

@Jack-Works
Copy link
Member

Please check out https://github.com/Jack-Works/proposal-freeze-arraybuffer-and-readonly-view thanks. I hope it can be integrated with R&T

@rricard
Copy link
Member

rricard commented Jul 8, 2022

In order to focus on changes that are necessary to finish this proposal, we are closing issues related to follow-on proposals. You are free to continue the discussion here and reference it in other venues.

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

No branches or pull requests

5 participants