<p dir="ltr">Thank you for testing this out Chen!<br>
A number of other people were able to reproduce the on heap results so not sure what to say here but thats the less important conclusion I think.<br>
For off heap, having the memory segment as a final field sounds like something that can be relevant for a very few niche use cases, if at all...<br>
If this cant be optimized further, without the final, this means a significant performance hit for a lot of use cases... off the top of my head, libraries like zstd and gzip that do jni bindings</p>
<br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Fri, Apr 18, 2025, 01:17 Chen Liang <<a href="mailto:chen.l.liang@oracle.com">chen.l.liang@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">
<div style="font-family:"Calibri Light","Helvetica Light",sans-serif;font-size:12pt;color:rgb(0,0,0)">
Hello, I think the observed performance difference is probably due to the heap array being static final. I tested on latest mainline, and ffm is consistently slower without a static final object that it can constant fold against: it exhibited similar performance
for auto arena 100 vs byte array 100, both having a significant overhead compared to Unsafe, unless the byte array is a constant (in a static final field). Meanwhile, I cannot reproduce FFM being faster than Unsafe for heap access: in the best case FFM is
still slightly slower than Unsafe.</div>
<div style="font-family:"Calibri Light","Helvetica Light",sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:"Calibri Light","Helvetica Light",sans-serif;font-size:12pt;color:rgb(0,0,0)">
For context, I used the source code at <a href="https://github.com/tomerr90/UnsafeVSFMA/blob/main/src/main/java/org/example/FMASerDe.java" target="_blank" rel="noreferrer">
https://github.com/tomerr90/UnsafeVSFMA/blob/main/src/main/java/org/example/FMASerDe.java</a> and edited around. I recommend testing against 22 or later releases where FFM has finalized; the preview feature on 21 is no longer maintained.</div>
<div style="font-family:"Calibri Light","Helvetica Light",sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:"Calibri Light","Helvetica Light",sans-serif;font-size:12pt;color:rgb(0,0,0)">
Regards, Chen Liang</div>
<div id="m_3079841704662508623appendonsend"></div>
<hr style="display:inline-block;width:98%">
<div id="m_3079841704662508623divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> panama-dev <<a href="mailto:panama-dev-retn@openjdk.org" target="_blank" rel="noreferrer">panama-dev-retn@openjdk.org</a>> on behalf of Tomer Zeltzer <<a href="mailto:tomerr90@gmail.com" target="_blank" rel="noreferrer">tomerr90@gmail.com</a>><br>
<b>Sent:</b> Thursday, April 17, 2025 6:31 AM<br>
<b>To:</b> <a href="mailto:panama-dev@openjdk.org" target="_blank" rel="noreferrer">panama-dev@openjdk.org</a> <<a href="mailto:panama-dev@openjdk.org" target="_blank" rel="noreferrer">panama-dev@openjdk.org</a>><br>
<b>Subject:</b> Potential performance regression with FFM compared to Unsafe</font>
<div> </div>
</div>
<div>
<div dir="auto">Hey all!
<div dir="auto">First time emailing such a list so apologies if somwthing is "off protocol".</div>
<div dir="auto">I wrote the following article where I benchmarked FFM and Unsafe in JDK21</div>
<div dir="auto"><a href="https://itnext.io/javas-new-fma-renaissance-or-decay-372a2aee5f32" target="_blank" rel="noreferrer">https://itnext.io/javas-new-fma-renaissance-or-decay-372a2aee5f32</a></div>
<div dir="auto"><br>
</div>
<div dir="auto">Conclusions were that FFM was 42% faster for on heap accesses while 67% slower for off heap, which is a bit weird.</div>
<div dir="auto">Code is also linked in the article.</div>
<div dir="auto">Would love hearing your thoughts!</div>
</div>
</div>
</div>
</blockquote></div>