Open spotandjake opened 8 months ago
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.
Currently
toString
in theruntime/string
module rely's onconcat
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 astdlib/buffer
module into the language sincetoString
was written. It would make sense to implement a basicbuffer
implementation in the runtime so we can make use of buffers throughout thestdlib
andruntime
. I think this would also help with maintainability of thetoString
function long term.One note is the advantage to
concat
overtoString
, is currently ourstdlib/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 theautogrow
function to grow at a slower pace. This flag also might be useful in the future for other stdlib and runtime functions.