10 ms·
how to handle gc strings when most tools don't support wasm stringref?
by singularity2001 3y ago
how to handle gc strings when most tools don't support wasm stringref?
- davexunit 3y agoYeah the strings situation isn't so good right now. stringref is really good imo but different factions in the wasm group are opposed. The best way to represent strings right now is (array (mut i8)) for UTF-8 or WTF-8 data. In Guile Hoot we are using stringref because it's convenient for the compiler to be able to emit (string.const "foo") and such, but we then perform a post-pass to remove all stringref instructions and replace them with instructions that operate on i8 arrays so the resulting binaries are usable. This approach has the advantage that string contents are visible to wasm so internal string manipulation is fast, but the downside is that strings have to be copied when going across the host/wasm boundary. An alternative approach would be to fully rely on the host to provide strings utilizing extern refs. This avoids the copying at the boundary problem of the first approach, but it has the disadvantage that all string operations need to call the host, so internal string manipulation is slow.