[External] : Re: MemorySegment.ofAddress(...).reinterpret(...)

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Mon Jul 10 10:48:57 UTC 2023


On 06/07/2023 23:19, Brian S O'Neill wrote:
> When I use the "ALL" MemorySegment instead of allocating 
> MemorySegments on the fly for copies, the performance regression drops 
> to ~2%. When I revert to using unsafe native field accesses (getInt, 
> etc) and unsafe memory copies, the performance is back to what it was 
> before (+/- 0.0019%). 

I assume that you also use ALL for native field accesses, as in:

ALL.get(JAVA_INT, long_offset)

Right?

The numbers here:

https://github.com/openjdk/panama-foreign/pull/844

Seem to show that while performance of copy can be improved a little by 
skipping the liveness check in certain cases (like in your ALL segment), 
that is not where the most gain is (probably because, in the bigger 
scheme of things, a liveness check in a bulk copy is a cheap thing which 
can easily be amortized).

But for single access (e.g. getInt) the difference is quite dramatic 
(and that is to be expected, as a single memory access often boils down 
to a single machine instruction, so anything on top of that would have 
visible consequences).

That said, this still assumes that the 2-3% regression you are seeing is 
due to a regression with the peak performance of your application (e.g. 
in jitted code). Unsafe is bound to be simply faster for the 
non-jitted/interpreted case.

I would recommend to try your application again with the above PR, and 
report back if you see any improvements. If you do not, then I think it 
might be a sign that we should start looking somewhere else (and perhaps 
also have some way to reproduce the performance regression you are 
observing).

Cheers
Maurizio



More information about the panama-dev mailing list