The new algorithm (copied below) is recursive and does not generate garbage for the construction of the array.
The allocation of the array to begin with is probably what wastes the most memory. Also, implementing this recursively might be a little risky because of stack overflows (and slower).
Something which would have more impact on space is to use a real Array to store the characters of a string. That way the String.fromCharCode.apply operation would not have to copy the array. Alternatively, we could implement an abstraction to allocate the internal array of characters, and mutate these arrays. There would be an implementation in pure JavaScript (using Arrays), and one for Tachyon.
I think we should leave is as-is for now, and eventually, I could write us a better system for manipulating and allocating strings, as described in my previous e-mail.
- Maxime