[External] : Re: MemorySegment APIs for reading and writing strings with known lengths
Liam Miller-Cushon
cushon at google.com
Mon Nov 10 14:20:21 UTC 2025
>
> I hope this comment was not in my doc?
>
It's a parenthetical in the paragraph starting with "Finally, ultimately,
the user is probably the most happy with an API that directly accepts the
units in which they are already measuring their string"
>
> You mean the _byte size_ of the encoded string (rather than number of code
> units?)
>
Yes, exactly.
> Something like this might be interesting. That said... if the charset
> matches, then creating the segment view, then obtaining its byte size is
> O(1) (e.g. no decoding). And if the charset doesn't match, you'll need to
> decode anyway -- at which point I'm not sure the array creation is really
> the bottleneck?
>
Thanks, yes, MemorySegment.ofString seemingly solves the case where the
charset matches, so it's more a question of whether there are performance
gains to be had for the case where the charset doesn't match. The
benchmarking I've seen suggests a carefully optimized loop over the string
is outperforming getBytes(charset).length for that case. I can do some more
analysis and report back.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/panama-dev/attachments/20251110/5bf9d25b/attachment-0001.htm>
More information about the panama-dev
mailing list