4 ms·
The conversion is required to properly support indexing for any index != 0. Optimizations are only possible if iterator-style APIs are used so the runtime can i
by samus 3y ago
The conversion is required to properly support indexing for any index != 0. Optimizations are only possible if iterator-style APIs are used so the runtime can iterate as well. However, it might be still more efficient to convert the whole string and be done with it, depending on its length. Languages with a proper WASM backend could offer optimized runtime libraries and/or optimize such code.
The issue is not new. JavaScript runtimes frequently use multiple optimized string types for various situations:
https://github.com/danbev/learning-v8/blob/master/notes/string.md https://github.com/danbev/learning-v8/blob/master/notes/stri...
- Someone 3y ago> Optimizations are only possible if iterator-style APIs are used They make it simpler, but it also is possible to detect that loops are iteration-style access in disguise. That takes time, so its more likely to happen in ahead of time compiled languages. C compilers can vectorize some of such loops, so they have logic for doing that.