<div dir="ltr"><div dir="ltr"><font color="#000000">Thank you Quân.</font><div><font color="#000000"><br></font><div><font color="#000000">All you saying guys make sense. </font></div><div><font color="#000000">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 color="#000000">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 color="#000000"><br></font></div><div><font color="#000000">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 color="#000000">The question of full dynamic with anonymous overloading is still unclear to me.</font></div><div><font color="#000000"><br></font></div><div>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">Benchmark <span class="gmail-Apple-converted-space"> </span>Mode<span class="gmail-Apple-converted-space"> </span>Cnt <span class="gmail-Apple-converted-space"> </span>Score <span class="gmail-Apple-converted-space"> </span>Error<span class="gmail-Apple-converted-space"> </span>Units</span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><b>OptionalComboIsPresentGet.opDynamicAnonymous <span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30<span class="gmail-Apple-converted-space"> </span>1059868995.937 ±<span class="gmail-Apple-converted-space"> </span>51273067.116<span class="gmail-Apple-converted-space"> </span>ops/s</b></span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">OptionalComboIsPresentGet.opJdk<span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30<span class="gmail-Apple-converted-space"> </span>1017505800.567 ±<span class="gmail-Apple-converted-space"> </span>16007847.872<span class="gmail-Apple-converted-space"> </span>ops/s</span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">OptionalComboIsPresentGet.opNestedStatic <span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30 <span class="gmail-Apple-converted-space"> </span>951493332.957 ±<span class="gmail-Apple-converted-space"> </span>12167812.398<span class="gmail-Apple-converted-space"> </span>ops/s</span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><br></span></p><p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">OptionalComboOfIsPresentGetTest.opDynamicAnonymous <span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30<span class="gmail-Apple-converted-space"> </span>1426348334.485 ±<span class="gmail-Apple-converted-space"> </span>20889455.433<span class="gmail-Apple-converted-space"> </span>ops/s</span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><b>OptionalComboOfIsPresentGetTest.opJdk<span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30<span class="gmail-Apple-converted-space"> </span>1435570789.822 ±<span class="gmail-Apple-converted-space"> </span>16587538.659<span class="gmail-Apple-converted-space"> </span>ops/s</b></span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">OptionalComboOfIsPresentGetTest.opNestedStatic <span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30<span class="gmail-Apple-converted-space"> </span>1418853644.215 ±<span class="gmail-Apple-converted-space"> </span>27755398.645<span class="gmail-Apple-converted-space"> </span>ops/s</span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><br></span></p><p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><b>OptionalComboOfNullableIsEmptyTest.opDynamicAnonymous<span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30<span class="gmail-Apple-converted-space"> </span>1434399595.592 ±<span class="gmail-Apple-converted-space"> </span>14749443.903<span class="gmail-Apple-converted-space"> </span>ops/s</b></span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">OptionalComboOfNullableIsEmptyTest.opJdk <span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30<span class="gmail-Apple-converted-space"> </span>1255375023.531 ± 107403119.573<span class="gmail-Apple-converted-space"> </span>ops/s</span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">OptionalComboOfNullableIsEmptyTest.opNestedStatic<span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30<span class="gmail-Apple-converted-space"> </span>1415705702.964 ±<span class="gmail-Apple-converted-space"> </span>26328318.672<span class="gmail-Apple-converted-space"> </span>ops/s</span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><br></span></p><p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">OptionalEmptyTest.opDynamicAnonymous <span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30<span class="gmail-Apple-converted-space"> </span>1417895521.763 ±<span class="gmail-Apple-converted-space"> </span>26311640.557<span class="gmail-Apple-converted-space"> </span>ops/s</span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><b>OptionalEmptyTest.opJdk<span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30<span class="gmail-Apple-converted-space"> </span>1423940087.962 ±<span class="gmail-Apple-converted-space"> </span>18515297.860<span class="gmail-Apple-converted-space"> </span>ops/s</b></span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">OptionalEmptyTest.opNestedStatic <span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30<span class="gmail-Apple-converted-space"> </span>1424779162.084 ±<span class="gmail-Apple-converted-space"> </span>20288793.337<span class="gmail-Apple-converted-space"> </span>ops/s</span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><br></span></p><p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">OptionalGetTest.emDynamicAnonymous <span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30<span class="gmail-Apple-converted-space"> </span>569132.235 ± <span class="gmail-Apple-converted-space"> </span>11089.903<span class="gmail-Apple-converted-space"> </span>ops/s</span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><b>OptionalGetTest.emJdk<span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30<span class="gmail-Apple-converted-space"> </span>549764.038 ± <span class="gmail-Apple-converted-space"> </span>14768.566<span class="gmail-Apple-converted-space"> </span>ops/s</b></span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">OptionalGetTest.emNestedStatic <span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30<span class="gmail-Apple-converted-space"> </span>568308.722 ±<span class="gmail-Apple-converted-space"> </span>6075.671<span class="gmail-Apple-converted-space"> </span>ops/s</span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><br></span></p><p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">OptionalGetTest.opDynamicAnonymous <span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30 <span class="gmail-Apple-converted-space"> </span>953788065.414 ± <span class="gmail-Apple-converted-space"> </span>7043419.784<span class="gmail-Apple-converted-space"> </span>ops/s</span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><b>OptionalGetTest.opJdk<span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30<span class="gmail-Apple-converted-space"> </span>1015679232.049 ±<span class="gmail-Apple-converted-space"> </span>11726562.032<span class="gmail-Apple-converted-space"> </span>ops/s</b></span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">OptionalGetTest.opNestedStatic <span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30 <span class="gmail-Apple-converted-space"> </span>944209513.151 ±<span class="gmail-Apple-converted-space"> </span>17718342.519<span class="gmail-Apple-converted-space"> </span>ops/s</span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><br></span></p><p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">OptionalIsPresentTest.emDynamicAnonymous <span class="gmail-Apple-converted-space" style=""> </span>thrpt <span class="gmail-Apple-converted-space" style=""> </span>30 <span class="gmail-Apple-converted-space" style=""> </span>869086292.481 ±<span class="gmail-Apple-converted-space" style=""> </span>11668636.886<span class="gmail-Apple-converted-space" style=""> </span>ops/s</span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><b>OptionalIsPresentTest.emJdk<span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30 <span class="gmail-Apple-converted-space"> </span>977042244.447 ±<span class="gmail-Apple-converted-space"> </span>44558020.220<span class="gmail-Apple-converted-space"> </span>ops/s</b></span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">OptionalIsPresentTest.emNestedStatic <span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30 <span class="gmail-Apple-converted-space"> </span>953424664.631 ± <span class="gmail-Apple-converted-space"> </span>8448564.963<span class="gmail-Apple-converted-space"> </span>ops/s</span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><br></span></p><p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">OptionalIsPresentTest.opDynamicAnonymous <span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30 <span class="gmail-Apple-converted-space"> </span>953285872.799 ± <span class="gmail-Apple-converted-space"> </span>6562894.941<span class="gmail-Apple-converted-space"> </span>ops/s</span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><b>OptionalIsPresentTest.opJdk<span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30<span class="gmail-Apple-converted-space"> </span>1006926903.885 ±<span class="gmail-Apple-converted-space"> </span>18055487.689<span class="gmail-Apple-converted-space"> </span>ops/s</b></span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">OptionalIsPresentTest.opNestedStatic <span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30 <span class="gmail-Apple-converted-space"> </span>954121471.431 ± <span class="gmail-Apple-converted-space"> </span>6829528.708<span class="gmail-Apple-converted-space"> </span>ops/s</span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><br></span></p><p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">OptionalOfNullableTest.emDynamicAnonymous<span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30<span class="gmail-Apple-converted-space"> </span>1422939780.266 ±<span class="gmail-Apple-converted-space"> </span>21693247.354<span class="gmail-Apple-converted-space"> </span>ops/s</span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><b>OptionalOfNullableTest.emJdk <span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30<span class="gmail-Apple-converted-space"> </span>1423340184.237 ±<span class="gmail-Apple-converted-space"> </span>21296444.017<span class="gmail-Apple-converted-space"> </span>ops/s</b></span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">OptionalOfNullableTest.emNestedStatic<span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30<span class="gmail-Apple-converted-space"> </span>1414965236.385 ±<span class="gmail-Apple-converted-space"> </span>26021734.344<span class="gmail-Apple-converted-space"> </span>ops/s</span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><br></span></p><p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">OptionalOfNullableTest.opDynamicAnonymous<span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30<span class="gmail-Apple-converted-space"> </span>1412594454.538 ±<span class="gmail-Apple-converted-space"> </span>28123612.298<span class="gmail-Apple-converted-space"> </span>ops/s</span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><b>OptionalOfNullableTest.opJdk <span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30<span class="gmail-Apple-converted-space"> </span>1427924599.589 ±<span class="gmail-Apple-converted-space"> </span>23469517.835<span class="gmail-Apple-converted-space"> </span>ops/s</b></span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">OptionalOfNullableTest.opNestedStatic<span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30<span class="gmail-Apple-converted-space"> </span>1420053175.637 ±<span class="gmail-Apple-converted-space"> </span>21170929.571<span class="gmail-Apple-converted-space"> </span>ops/s</span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><br></span></p><p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">OptionalOfTest.emDynamicAnonymous<span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30<span class="gmail-Apple-converted-space"> </span>549907.559 ± <span class="gmail-Apple-converted-space"> </span>14560.954<span class="gmail-Apple-converted-space"> </span>ops/s</span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">OptionalOfTest.emJdk <span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30<span class="gmail-Apple-converted-space"> </span>557858.903 ±<span class="gmail-Apple-converted-space"> </span>2851.076<span class="gmail-Apple-converted-space"> </span>ops/s</span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><b>OptionalOfTest.emNestedStatic<span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30<span class="gmail-Apple-converted-space"> </span>548655.854 ± <span class="gmail-Apple-converted-space"> </span>10875.674<span class="gmail-Apple-converted-space"> </span>ops/s</b></span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><br></span></p><p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">OptionalOfTest.opDynamicAnonymous<span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30<span class="gmail-Apple-converted-space"> </span>1411307270.435 ±<span class="gmail-Apple-converted-space"> </span>19832207.408<span class="gmail-Apple-converted-space"> </span>ops/s</span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">OptionalOfTest.opJdk <span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30<span class="gmail-Apple-converted-space"> </span>1400651442.726 ±<span class="gmail-Apple-converted-space"> </span>23641065.234<span class="gmail-Apple-converted-space"> </span>ops/s</span></p>
<p class="gmail-p1" 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 class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><b>OptionalOfTest.opNestedStatic<span class="gmail-Apple-converted-space"> </span>thrpt <span class="gmail-Apple-converted-space"> </span>30<span class="gmail-Apple-converted-space"> </span>1433953744.298 ±<span class="gmail-Apple-converted-space"> </span>21414147.936<span class="gmail-Apple-converted-space"> </span>ops/s</b></span></p></div><div><br></div></div><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:1px solid rgb(204,204,204);padding-left:1ex"><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:1px solid rgb(204,204,204);padding-left:1ex"><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>