-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Consider making breaking change of making dart:io
APIs return deeply immutable bytes.
#50069
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
Comments
If you can pull it off, I have no problem with the change. Do we have a proper unmodifiable |
We could consider if there is a path to making this opt-in or configurable in some way, e.g. through a separate set of APIs or through some annotation or language version (somehow)? Then we don't have to bother about it being breaking. |
We do - at least in the VM. The trick is to generate a backing, a Our C API exposes this functionality, see We would a similar mechanism for
I think doing so may be feasible, at the expense of clean API. Though for us to actually benefit, we'd need to go through If we on the other hand, decided to change the semantics to return immutable bytes, we only need to update very few places that actually need a writable bytes. The price we pay here is that for those use cases, we have to make mutable copies. @lrhn wdyt? Someone could do a trial of this in g3 and see how many places would need updating (one place I'm aware of is the |
The VM has support for sharing deeply immutable typed data across isolates. Though it is cumbersome to create such deeply immutable typed data - especially if one wants to avoid an additional copy (see e.g. dart-lang/sdk/issues/50068).
Many typed data instances originate from outside dart code (e.g. loaded from filesystem, socket / http, etc). When that data is read, it is very rarely modified.
So I propose making all
dart:io
APIs return deeply immutable bytes. It would be a breaking change due to a very small percent of use cases where such data is actually modified, those places would need to be updated.Though the benefit (all
dart:io
returned bytes are sharable across isolates by-pointer) seems to outweigh the cost to me (very rare case of modifying such bytes).The breaking change would not necessarily imply we have to change the actual types of the API (though that would be an option)
/cc @lrhn opinions?
The text was updated successfully, but these errors were encountered: