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

Rework: toString to use a buffer #2087

Open
spotandjake opened this issue Apr 5, 2024 · 1 comment
Open

Rework: toString to use a buffer #2087

spotandjake opened this issue Apr 5, 2024 · 1 comment
Assignees
Labels

Comments

@spotandjake
Copy link
Member

spotandjake commented Apr 5, 2024

Currently toString in the runtime/string module rely's on concat for building the output string, this often incurs a performance penality from the many allocations done especially with more complex data structures like nested records. We implemented the bytes literal and a stdlib/buffer module into the language since toString was written. It would make sense to implement a basic buffer implementation in the runtime so we can make use of buffers throughout the stdlib and runtime. I think this would also help with maintainability of the toString function long term.

One note is the advantage to concat over toString, is currently our stdlib/buffer grows by powers of 2, in a memory confined environment this behaviour might not be ideal, we could add a new compiler flag though such as --low-memory which could configure the autogrow function to grow at a slower pace. This flag also might be useful in the future for other stdlib and runtime functions.

@spotandjake spotandjake self-assigned this Apr 5, 2024
@ospencer
Copy link
Member

ospencer commented Apr 5, 2024

To be clear, concat takes a list of strings and returns one large string—it's not concatenating two strings over and over. This would remove the allocations for the list cons cells which would be a large improvement, but not a dramatic one.

I do not think we should add a compiler flag to modify the growth behavior. It's complexity we don't need right now and would show little benefit. Switching to a buffer already improves memory consumption a lot.

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

No branches or pull requests

2 participants