Skip to content

Conversation

@hardlyardi
Copy link

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.
Copy link
Contributor

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.

Copy link
Author

@hardlyardi hardlyardi Dec 30, 2025

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

Comment on lines +5 to +6
Adds two new functions; `buffer.freeze(buf)` for creating a "read-only" buffer, and `buffer.isfrozen` to check if a
buffer is frozen.
Copy link
Contributor

@alexmccord alexmccord Dec 30, 2025

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.

Copy link
Contributor

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.

Copy link
Author

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.

@MagmaBurnsV
Copy link
Contributor

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 buffer.tostring.

@jackdotink
Copy link
Contributor

The problem is that string APIs are an order of magnitude slower than buffer APIs. Buffers are always better, even for immutable data.

@vegorov-rbx
Copy link
Collaborator

Suggestion for this feature has been made before and our answer remains the same.
We do not have plans to introduce freezing for buffers because of the performance consideration for the additional checks, impact on code size and incompatibility with existing Luau C API for buffer access (which cannot enforce immutability because modifications are not going through API).

@vegorov-rbx vegorov-rbx closed this Jan 3, 2026
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.

5 participants