<div dir="auto">Tbh I have a hard time understand what you are trying to convey. Please write grammatically correct sentences with clear structure.</div><div dir="auto"><br></div><div dir="auto">I notice you attach benchmark results but I don't see what was benchmarked to produce those results.</div><div dir="auto"><br></div><div dir="auto">Another point is that Value classes has not been delivered yet, so there are potential performance uplifts of Optional in the future. This may not be possible if Optional is polymorphic.</div><div dir="auto"><br></div><div dir="auto">Thanks</div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 28 Aug 2023 at 18:27, Oleksii Kucheruk <<a href="mailto:iselo%2Bopenjdk@raccoons.co">iselo+openjdk@raccoons.co</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)"><div dir="ltr"><div dir="ltr"><font style="color:rgb(0,0,0)">Thank you Quân.</font><div><font style="color:rgb(0,0,0)"><br></font><div><font style="color:rgb(0,0,0)">All  you saying guys make sense. </font></div><div><font style="color:rgb(0,0,0)">Yes there is a difference calling methods by pointer and involving vtable. But one thing didn't came out of my head:</font></div><div><font style="color:rgb(0,0,0)">If virtual dispatch dispatch is 10-time more expensive and polymorphism is a performance killer so how combinations of "return optional - isPresent- get" or "return empty - isEmpty" with virtual dispatch and memory allocation for every empty or sole but polymorph empty could perform equally or even beat the near zero-cost abstraction of Value classes according to JMH?</font></div></div><div><font style="color:rgb(0,0,0)"><br></font></div><div><font style="color:rgb(0,0,0)">Maybe private final static nested EmptyOptional invokevirtual bytecode<span style="font-family:"Bitstream Vera Sans","Luxi Sans",Helvetica,Arial,san-serif"> refers a</span> final methods and it need not have a vtable slot allocated. This means that, after linking, an invokevirtual bytecode might in fact collapse into the equivalent of an invokestatic bytecode.</font></div><div><font style="color:rgb(0,0,0)">The question of full dynamic with anonymous overloading is still unclear to me.</font></div><div><font style="color:rgb(0,0,0)"><br></font></div><div>





<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo">Benchmark <span style="font-family:Menlo">                                              </span>Mode<span style="font-family:Menlo">  </span>Cnt <span style="font-family:Menlo">          </span>Score <span style="font-family:Menlo">          </span>Error<span style="font-family:Menlo">  </span>Units</span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo"><b style="font-family:Menlo">OptionalComboIsPresentGet.opDynamicAnonymous <span style="font-family:Menlo">          </span>thrpt <span style="font-family:Menlo">  </span>30<span style="font-family:Menlo">  </span>1059868995.937 ±<span style="font-family:Menlo">  </span>51273067.116<span style="font-family:Menlo">  </span>ops/s</b></span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo">OptionalComboIsPresentGet.opJdk<span style="font-family:Menlo">                        </span>thrpt <span style="font-family:Menlo">  </span>30<span style="font-family:Menlo">  </span>1017505800.567 ±<span style="font-family:Menlo">  </span>16007847.872<span style="font-family:Menlo">  </span>ops/s</span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo">OptionalComboIsPresentGet.opNestedStatic <span style="font-family:Menlo">              </span>thrpt <span style="font-family:Menlo">  </span>30 <span style="font-family:Menlo">  </span>951493332.957 ±<span style="font-family:Menlo">  </span>12167812.398<span style="font-family:Menlo">  </span>ops/s</span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo"><br></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo">OptionalComboOfIsPresentGetTest.opDynamicAnonymous <span style="font-family:Menlo">    </span>thrpt <span style="font-family:Menlo">  </span>30<span style="font-family:Menlo">  </span>1426348334.485 ±<span style="font-family:Menlo">  </span>20889455.433<span style="font-family:Menlo">  </span>ops/s</span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo"><b style="font-family:Menlo">OptionalComboOfIsPresentGetTest.opJdk<span style="font-family:Menlo">                  </span>thrpt <span style="font-family:Menlo">  </span>30<span style="font-family:Menlo">  </span>1435570789.822 ±<span style="font-family:Menlo">  </span>16587538.659<span style="font-family:Menlo">  </span>ops/s</b></span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo">OptionalComboOfIsPresentGetTest.opNestedStatic <span style="font-family:Menlo">        </span>thrpt <span style="font-family:Menlo">  </span>30<span style="font-family:Menlo">  </span>1418853644.215 ±<span style="font-family:Menlo">  </span>27755398.645<span style="font-family:Menlo">  </span>ops/s</span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo"><br></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo"><b style="font-family:Menlo">OptionalComboOfNullableIsEmptyTest.opDynamicAnonymous<span style="font-family:Menlo">  </span>thrpt <span style="font-family:Menlo">  </span>30<span style="font-family:Menlo">  </span>1434399595.592 ±<span style="font-family:Menlo">  </span>14749443.903<span style="font-family:Menlo">  </span>ops/s</b></span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo">OptionalComboOfNullableIsEmptyTest.opJdk <span style="font-family:Menlo">              </span>thrpt <span style="font-family:Menlo">  </span>30<span style="font-family:Menlo">  </span>1255375023.531 ± 107403119.573<span style="font-family:Menlo">  </span>ops/s</span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo">OptionalComboOfNullableIsEmptyTest.opNestedStatic<span style="font-family:Menlo">      </span>thrpt <span style="font-family:Menlo">  </span>30<span style="font-family:Menlo">  </span>1415705702.964 ±<span style="font-family:Menlo">  </span>26328318.672<span style="font-family:Menlo">  </span>ops/s</span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo"><br></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo">OptionalEmptyTest.opDynamicAnonymous <span style="font-family:Menlo">                  </span>thrpt <span style="font-family:Menlo">  </span>30<span style="font-family:Menlo">  </span>1417895521.763 ±<span style="font-family:Menlo">  </span>26311640.557<span style="font-family:Menlo">  </span>ops/s</span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo"><b style="font-family:Menlo">OptionalEmptyTest.opJdk<span style="font-family:Menlo">                                </span>thrpt <span style="font-family:Menlo">  </span>30<span style="font-family:Menlo">  </span>1423940087.962 ±<span style="font-family:Menlo">  </span>18515297.860<span style="font-family:Menlo">  </span>ops/s</b></span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo">OptionalEmptyTest.opNestedStatic <span style="font-family:Menlo">                      </span>thrpt <span style="font-family:Menlo">  </span>30<span style="font-family:Menlo">  </span>1424779162.084 ±<span style="font-family:Menlo">  </span>20288793.337<span style="font-family:Menlo">  </span>ops/s</span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo"><br></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo">OptionalGetTest.emDynamicAnonymous <span style="font-family:Menlo">                    </span>thrpt <span style="font-family:Menlo">  </span>30<span style="font-family:Menlo">      </span>569132.235 ± <span style="font-family:Menlo">    </span>11089.903<span style="font-family:Menlo">  </span>ops/s</span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo"><b style="font-family:Menlo">OptionalGetTest.emJdk<span style="font-family:Menlo">                                  </span>thrpt <span style="font-family:Menlo">  </span>30<span style="font-family:Menlo">      </span>549764.038 ± <span style="font-family:Menlo">    </span>14768.566<span style="font-family:Menlo">  </span>ops/s</b></span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo">OptionalGetTest.emNestedStatic <span style="font-family:Menlo">                        </span>thrpt <span style="font-family:Menlo">  </span>30<span style="font-family:Menlo">      </span>568308.722 ±<span style="font-family:Menlo">      </span>6075.671<span style="font-family:Menlo">  </span>ops/s</span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo"><br></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo">OptionalGetTest.opDynamicAnonymous <span style="font-family:Menlo">                    </span>thrpt <span style="font-family:Menlo">  </span>30 <span style="font-family:Menlo">  </span>953788065.414 ± <span style="font-family:Menlo">  </span>7043419.784<span style="font-family:Menlo">  </span>ops/s</span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo"><b style="font-family:Menlo">OptionalGetTest.opJdk<span style="font-family:Menlo">                                  </span>thrpt <span style="font-family:Menlo">  </span>30<span style="font-family:Menlo">  </span>1015679232.049 ±<span style="font-family:Menlo">  </span>11726562.032<span style="font-family:Menlo">  </span>ops/s</b></span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo">OptionalGetTest.opNestedStatic <span style="font-family:Menlo">                        </span>thrpt <span style="font-family:Menlo">  </span>30 <span style="font-family:Menlo">  </span>944209513.151 ±<span style="font-family:Menlo">  </span>17718342.519<span style="font-family:Menlo">  </span>ops/s</span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo"><br></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo">OptionalIsPresentTest.emDynamicAnonymous <span style="font-family:Menlo">              </span>thrpt <span style="font-family:Menlo">  </span>30 <span style="font-family:Menlo">  </span>869086292.481 ±<span style="font-family:Menlo">  </span>11668636.886<span style="font-family:Menlo">  </span>ops/s</span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo"><b style="font-family:Menlo">OptionalIsPresentTest.emJdk<span style="font-family:Menlo">                            </span>thrpt <span style="font-family:Menlo">  </span>30 <span style="font-family:Menlo">  </span>977042244.447 ±<span style="font-family:Menlo">  </span>44558020.220<span style="font-family:Menlo">  </span>ops/s</b></span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo">OptionalIsPresentTest.emNestedStatic <span style="font-family:Menlo">                  </span>thrpt <span style="font-family:Menlo">  </span>30 <span style="font-family:Menlo">  </span>953424664.631 ± <span style="font-family:Menlo">  </span>8448564.963<span style="font-family:Menlo">  </span>ops/s</span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo"><br></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo">OptionalIsPresentTest.opDynamicAnonymous <span style="font-family:Menlo">              </span>thrpt <span style="font-family:Menlo">  </span>30 <span style="font-family:Menlo">  </span>953285872.799 ± <span style="font-family:Menlo">  </span>6562894.941<span style="font-family:Menlo">  </span>ops/s</span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo"><b style="font-family:Menlo">OptionalIsPresentTest.opJdk<span style="font-family:Menlo">                            </span>thrpt <span style="font-family:Menlo">  </span>30<span style="font-family:Menlo">  </span>1006926903.885 ±<span style="font-family:Menlo">  </span>18055487.689<span style="font-family:Menlo">  </span>ops/s</b></span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo">OptionalIsPresentTest.opNestedStatic <span style="font-family:Menlo">                  </span>thrpt <span style="font-family:Menlo">  </span>30 <span style="font-family:Menlo">  </span>954121471.431 ± <span style="font-family:Menlo">  </span>6829528.708<span style="font-family:Menlo">  </span>ops/s</span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo"><br></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo">OptionalOfNullableTest.emDynamicAnonymous<span style="font-family:Menlo">              </span>thrpt <span style="font-family:Menlo">  </span>30<span style="font-family:Menlo">  </span>1422939780.266 ±<span style="font-family:Menlo">  </span>21693247.354<span style="font-family:Menlo">  </span>ops/s</span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo"><b style="font-family:Menlo">OptionalOfNullableTest.emJdk <span style="font-family:Menlo">                          </span>thrpt <span style="font-family:Menlo">  </span>30<span style="font-family:Menlo">  </span>1423340184.237 ±<span style="font-family:Menlo">  </span>21296444.017<span style="font-family:Menlo">  </span>ops/s</b></span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo">OptionalOfNullableTest.emNestedStatic<span style="font-family:Menlo">                  </span>thrpt <span style="font-family:Menlo">  </span>30<span style="font-family:Menlo">  </span>1414965236.385 ±<span style="font-family:Menlo">  </span>26021734.344<span style="font-family:Menlo">  </span>ops/s</span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo"><br></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo">OptionalOfNullableTest.opDynamicAnonymous<span style="font-family:Menlo">              </span>thrpt <span style="font-family:Menlo">  </span>30<span style="font-family:Menlo">  </span>1412594454.538 ±<span style="font-family:Menlo">  </span>28123612.298<span style="font-family:Menlo">  </span>ops/s</span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo"><b style="font-family:Menlo">OptionalOfNullableTest.opJdk <span style="font-family:Menlo">                          </span>thrpt <span style="font-family:Menlo">  </span>30<span style="font-family:Menlo">  </span>1427924599.589 ±<span style="font-family:Menlo">  </span>23469517.835<span style="font-family:Menlo">  </span>ops/s</b></span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo">OptionalOfNullableTest.opNestedStatic<span style="font-family:Menlo">                  </span>thrpt <span style="font-family:Menlo">  </span>30<span style="font-family:Menlo">  </span>1420053175.637 ±<span style="font-family:Menlo">  </span>21170929.571<span style="font-family:Menlo">  </span>ops/s</span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo"><br></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo">OptionalOfTest.emDynamicAnonymous<span style="font-family:Menlo">                      </span>thrpt <span style="font-family:Menlo">  </span>30<span style="font-family:Menlo">      </span>549907.559 ± <span style="font-family:Menlo">    </span>14560.954<span style="font-family:Menlo">  </span>ops/s</span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo">OptionalOfTest.emJdk <span style="font-family:Menlo">                                  </span>thrpt <span style="font-family:Menlo">  </span>30<span style="font-family:Menlo">      </span>557858.903 ±<span style="font-family:Menlo">      </span>2851.076<span style="font-family:Menlo">  </span>ops/s</span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo"><b style="font-family:Menlo">OptionalOfTest.emNestedStatic<span style="font-family:Menlo">                          </span>thrpt <span style="font-family:Menlo">  </span>30<span style="font-family:Menlo">      </span>548655.854 ± <span style="font-family:Menlo">    </span>10875.674<span style="font-family:Menlo">  </span>ops/s</b></span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo"><br></span></p><p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo">OptionalOfTest.opDynamicAnonymous<span style="font-family:Menlo">                      </span>thrpt <span style="font-family:Menlo">  </span>30<span style="font-family:Menlo">  </span>1411307270.435 ±<span style="font-family:Menlo">  </span>19832207.408<span style="font-family:Menlo">  </span>ops/s</span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo">OptionalOfTest.opJdk <span style="font-family:Menlo">                                  </span>thrpt <span style="font-family:Menlo">  </span>30<span style="font-family:Menlo">  </span>1400651442.726 ±<span style="font-family:Menlo">  </span>23641065.234<span style="font-family:Menlo">  </span>ops/s</span></p>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;font-kerning:auto;font-feature-settings:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;font-family:Menlo"><b style="font-family:Menlo">OptionalOfTest.opNestedStatic<span style="font-family:Menlo">                          </span>thrpt <span style="font-family:Menlo">  </span>30<span style="font-family:Menlo">  </span>1433953744.298 ±<span style="font-family:Menlo">  </span>21414147.936<span style="font-family:Menlo">  </span>ops/s</b></span></p></div><div><br></div></div></div><div dir="ltr"><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Aug 28, 2023 at 11:13 AM Quân Anh Mai <<a href="mailto:anhmdq@gmail.com" target="_blank">anhmdq@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)"><div dir="auto">Hi,</div><div dir="auto"><br></div><div dir="auto">Polymorphism is a performance killer. Normally this does not matter much, but for thin wrappers such as Optional, this is one of the most important factor.</div><div dir="auto"><br></div><div dir="auto">Behaviour polymorphism requires virtual dispatch and prevents inlining. This is really detrimental, as simple operations such as a getter which is previously only consisted of a memory load, in the presence of polymorphism would have to go through a 10-time more expensive virtual dispatch. Function calls, especially virtual ones, are also opaque and prohibit compiler optimisations.</div><div dir="auto"><br></div><div dir="auto">Layout polymorphism prevents direct accesses and requires indirection. This means that for every instance of Optional created a memory allocation is required. Optional is expected to be a near zero-cost abstraction in the presence of Value classes, so making it polymorphic is unacceptable.</div><div dir="auto"><br></div><div dir="auto">Thanks.</div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 23 Aug 2023 at 22:43, Oleksii Kucheruk <<a href="mailto:iselo%2Bopenjdk@raccoons.co" target="_blank">iselo+openjdk@raccoons.co</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)"><div dir="ltr">Hi there.<div>I have found that `java.util.Optional` is written procedural style and has `ifnonnull`  checks in each method. I propose to refactor `Optional` in accordance to OOP-style. This will eliminates all unnecessary `if`-statements, removes duplications and reduces bytecode size more then twice.</div><div><br></div><div>I have two solutions:</div><div>1. Completely dynamic that avoids single static `EMPTY` instance and unchecked casting of each `Optional.empty()`</div><div>2. Preserving original single static `EMPTY` per VM.</div><div><br></div><div>Also there are couple methods that throws NPE due to calling methods on null-objects and requires to add `Objects.requireNonNull(...)`.</div><div><br></div><div>OptionalInt, OptionalDouble, OptionalLong could be refactored same way even with remove of additional boolean variable `isPresent`.</div><div><br></div><div>Since I'm new here any guidance will be helpful.</div><div>Thank you in advance.</div></div>
</blockquote></div></div>
</blockquote></div>
</div>
</blockquote></div></div>