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

fromWtf8Array with no start/length parameters ? #9

Open
wingo opened this issue Oct 17, 2023 · 1 comment
Open

fromWtf8Array with no start/length parameters ? #9

wingo opened this issue Oct 17, 2023 · 1 comment

Comments

@wingo
Copy link
Contributor

wingo commented Oct 17, 2023

My understanding is that the interface to fromWtf8Array was taken from stringref, where the use case might be, you have a buffered I/O port with an (array i8) holding your bytes, and you want to decode a part of that buffer. In that case it definitely makes sense to take a start and an offset.

However for wtf-8 string conversion on the boundary, for languages that use UTF-8 or WTF-8 internally -- i.e., where you're not using externref to actually represent the strings, but instead you are using the JS string builtins to perform a more efficient encode/decode when communicating with the host -- there, you are much more likely to just have a full (array i8). You will be decoding the whole thing. In that case binary size and runtime overhead will be minimized if we can remove the start and end arguments, and just assume we transcode the whole buffer.

@eqrion
Copy link
Collaborator

eqrion commented Dec 5, 2023

@wingo Would this new function just be a short hand for:

(call $fromWtf8Array
  (i32.const 0)
  (array.length
    (local.get $arr)
  )
  (local.get $arr)
)

I can see that being a good binary size reduction (but would also be interested in some data).

runtime overhead

Are you imagining this operation would be more efficient than the version operating on a slice?

@eqrion eqrion mentioned this issue Dec 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants