Skip to content

stirng.encode_wtf16_array with start/end #49

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

Open
gkdn opened this issue Sep 16, 2022 · 3 comments
Open

stirng.encode_wtf16_array with start/end #49

gkdn opened this issue Sep 16, 2022 · 3 comments

Comments

@gkdn
Copy link

gkdn commented Sep 16, 2022

I noticed that string.encode_wtf16_array is not accepting the string range to encode (like sourceStartIndex and sourceEndIndex).
Is it efficient enough to do a slice first and then call encode_wtf16_array or would it be worthwhile to take additional parameters to encode_wtf16_array?

@gkdn
Copy link
Author

gkdn commented Sep 17, 2022

@jakobkummerow

@jakobkummerow
Copy link
Collaborator

Creating a slice should be fairly cheap (allocation of a small object, could possibly be optimized out by engines in the long run). I'm also fine with adding parameters to encode_wtf16_array, or having a second version of that instruction that takes such parameters. Either way that instruction would probably belong in the world of stringview_wtf16 then.

I think it mostly boils down to: which scenario is more common in practice?

  • wanting to encode an entire string, without having to spend binary size on providing (0, length) as range?
  • wanting to encode part of a string, without having to explicitly create a slice first?

If it helps, we could also implement the second version as an experiment, then you could test with microbenchmarks to see if it makes a measurable difference.

@gkdn
Copy link
Author

gkdn commented Sep 17, 2022

I don't think there will be any concerns around binary size here so it is ok to if there is only one instruction.

If the slice is effectively a view, I'm also not much concerned around the performance but if you would like to experiment in any case I can quickly adapt and provide you some numbers.

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