On Wed, 14 Oct 2026 11:27:04 GMT, Maurizio Cimadamore <[email protected]> 
wrote:

> and vector is incubating, so references to vector API types from String are 
> not really possible

Yes, I think that's the crux of it. I wondered if once Vector is non-incubating 
perhaps the Vector-returning methods could be directly in JLA, but I haven't 
tried that.

I switched to a read-only view based on Alan's comment about using the mutable 
`byte[]`.

One short-term alternative might be to keep this out of JLA and create a 
separate accessor that's only visible to `jdk.incubator.vector` instead of to 
everything that can use JLA.

> Why this? Is this to avoid calling "asReadOnly" ?

Yes. I was worried about whether `asReadOnly()` would get inlined and optimized 
away, and in general about whether using the read-only `MemorySegment` (instead 
of `fromArray`) would add performance overhead.

I think `asReadOnly()` could theoretically affect inlining thresholds, but I'm 
not sure how much this matters in practice, I'll double-check.

> I notice here that you have two options: get a segment view and use that... 
> or obtain the byte[] and pass that to fromArray. I'm not sure which is better 
> -- the segment path allows you to model it as a read only segment, but it's 
> also less direct.

I was worried that the segment view would be slower, but at least in the 
benchmarks I ran there was basically no difference between the segment and the 
array. If there was an acceptable way to access the `byte[]` I think it could 
make sense to use that instead though. (I think going through `MemorySegment` 
might still be necessary for the case where UTF-16 is loaded into a 
`ShortVector`.)

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/32373#discussion_r4270387063
PR Review Comment: https://git.openjdk.org/jdk/pull/32373#discussion_r4270389790
PR Review Comment: https://git.openjdk.org/jdk/pull/32373#discussion_r4270395008

Reply via email to