-
Notifications
You must be signed in to change notification settings - Fork 73
[RFC] buffer.freeze
#164
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
[RFC] buffer.freeze
#164
Conversation
docs/buffer-freezing.md
Outdated
| when it comes to dealing with buffers, but the inverse argument can be made - immutable buffers could actually lead to | ||
| VM/NCG/Runtime performance optimizations. | ||
| - This increases the number of standard library functions, which naturally makes the language harder to "learn". More | ||
| importantly, `buffer.freeze` / `buffer.isfrozen` might take up a fastcall slot in the VM. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I doubt these two functions are worth the remaining valuable slots.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think there'll always be some demand, but i'll remove that bit since those usually would not be in hotpaths (also they'd always be fastcall1). the only one that imo could be worth considering is isfrozen
| Adds two new functions; `buffer.freeze(buf)` for creating a "read-only" buffer, and `buffer.isfrozen` to check if a | ||
| buffer is frozen. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How will this interact with buffer slices? Freezing a buffer slice is kind of nonsensical due to memory aliasing, which probably means buffer slices aren't buffers, they're a different primitive altogether.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this probably means that buffer freezing is a bad idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How will this interact with buffer slices? Freezing a buffer slice is kind of nonsensical due to memory aliasing, which probably means buffer slices aren't
buffers, they're a different primitive altogether.
buffer slices are not currently a feature. I am aware of the conflict, but wrote this up anyways to get the discussion about immutability and buffers out there - I think frozencopy would probably be a viable alternative.
|
I think buffers should act as the mutable variant of packed strings and have little utility in being readonly. If someone wants an immutable buffer, they can just use |
|
The problem is that string APIs are an order of magnitude slower than buffer APIs. Buffers are always better, even for immutable data. |
|
Suggestion for this feature has been made before and our answer remains the same. |
Rendered.