<div dir="ltr">Indeed Bela, you&#39;re an extreme naysayer! :)<div><br></div><div>I&#39;m actually trying to get as many comments and arguments out of this discussion. I hope we will be able to iron out a general recommendation or approach how we want to treat Optionals.<br><br><div class="gmail_quote"><div dir="ltr">On Tue, May 23, 2017 at 10:14 PM Bela Ban &lt;<a href="mailto:belaban@mailbox.org">belaban@mailbox.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Actually, I&#39;m an extreme naysayer! I actually voiced concerns so I&#39;m<br>
wondering where your assumption there are no naysayers is coming from... :-)<br>
<br>
<br>
On 23/05/17 1:54 PM, Sebastian Laskawiec wrote:<br>
&gt; Hey!<br>
&gt;<br>
&gt; So I think we have no extreme naysayers to Optional. So let me try to<br>
&gt; sum up what we have achieved so:<br>
&gt;<br>
&gt;   * In macroscale benchmark based on REST interface using Optionals<br>
&gt;     didn&#39;t lower the performance.<br>
&gt;   * +1 for using it in public APIs, especially for those using<br>
&gt;     functional style.<br>
&gt;   * Creating lots of Optional instances might add some pressure on GC,<br>
&gt;     so we need to be careful when using them in hot code paths. In<br>
&gt;     such cases it is required to run a micro scale benchamark to make<br>
&gt;     sure the performance didn&#39;t drop. The microbenchmark should also<br>
&gt;     be followed by macro scale benchamrk - PerfJobAck. Also, keep an<br>
&gt;     eye on Eden space in such cases.<br>
&gt;<br>
&gt; If you agree with me, and there are no hard evidence that using<br>
&gt; Optional degrade performance significantly, I would like to issue a<br>
&gt; pull request and put those findings into contributing guide [1].<br>
&gt;<br>
&gt; Thanks,<br>
&gt; Sebastian<br>
&gt;<br>
&gt; [1]<br>
&gt; <a href="https://github.com/infinispan/infinispan/tree/master/documentation/src/main/asciidoc/contributing" rel="noreferrer" target="_blank">https://github.com/infinispan/infinispan/tree/master/documentation/src/main/asciidoc/contributing</a><br>
&gt;<br>
&gt; On Mon, May 22, 2017 at 6:36 PM Galder Zamarreño &lt;<a href="mailto:galder@redhat.com" target="_blank">galder@redhat.com</a><br>
&gt; &lt;mailto:<a href="mailto:galder@redhat.com" target="_blank">galder@redhat.com</a>&gt;&gt; wrote:<br>
&gt;<br>
&gt;     I think Sanne&#39;s right here, any differences in such large scale<br>
&gt;     test are hard to decipher.<br>
&gt;<br>
&gt;     Also, as mentioned in a previous email, my view on its usage is<br>
&gt;     same as Sanne&#39;s:<br>
&gt;<br>
&gt;     * Definitely in APIs/SPIs.<br>
&gt;     * Be gentle with it internals.<br>
&gt;<br>
&gt;     Cheers,<br>
&gt;     --<br>
&gt;     Galder Zamarreño<br>
&gt;     Infinispan, Red Hat<br>
&gt;<br>
&gt;     &gt; On 18 May 2017, at 14:35, Sanne Grinovero &lt;<a href="mailto:sanne@infinispan.org" target="_blank">sanne@infinispan.org</a><br>
&gt;     &lt;mailto:<a href="mailto:sanne@infinispan.org" target="_blank">sanne@infinispan.org</a>&gt;&gt; wrote:<br>
&gt;     &gt;<br>
&gt;     &gt; Hi Sebastian,<br>
&gt;     &gt;<br>
&gt;     &gt; sorry but I think you&#39;ve been wasting time, I hope it was fun :)<br>
&gt;     This is not the right methodology to &quot;settle&quot; the matter (unless<br>
&gt;     you want Radim&#39;s eyes to get bloody..).<br>
&gt;     &gt;<br>
&gt;     &gt; Any change in such a complex system will only affect the<br>
&gt;     performance metrics if you&#39;re actually addressing the dominant<br>
&gt;     bottleneck. In some cases it might be CPU, like if your system is<br>
&gt;     at 90%+ CPU then it&#39;s likely that reviewing the code to use less<br>
&gt;     CPU would be beneficial; but even that can be counter-productive,<br>
&gt;     for example if you&#39;re having contention caused by optimistic<br>
&gt;     locking and you fail to address that while making something else<br>
&gt;     &quot;faster&quot; the performance loss on the optimistic lock might become<br>
&gt;     asymptotic.<br>
&gt;     &gt;<br>
&gt;     &gt; A good reason to avoid excessive usage of Optional (and<br>
&gt;     *excessive* doesn&#39;t mean a couple dozen in a millions lines of<br>
&gt;     code..) is to not run out of eden space, especially for all the<br>
&gt;     code running in interpreted mode.<br>
&gt;     &gt;<br>
&gt;     &gt; In your case you&#39;ve been benchmarking a hugely complex beast,<br>
&gt;     not least over REST! When running the REST Server I doubt that<br>
&gt;     allocation in eden is your main problem. You just happened to have<br>
&gt;     a couple Optionals on your path; sure performance changed but<br>
&gt;     there&#39;s no enough data in this way to figure out what exactly<br>
&gt;     happened:<br>
&gt;     &gt;  - did it change at all or was it just because of a lucky<br>
&gt;     optimisation? (The JIT will always optimise stuff differently even<br>
&gt;     when re-running the same code)<br>
&gt;     &gt;  - did the overall picture improve because this code became much<br>
&gt;     *less* slower?<br>
&gt;     &gt;<br>
&gt;     &gt; The real complexity in benchmarking is to accurately understand<br>
&gt;     why it changed; this should also tell you why it didn&#39;t change<br>
&gt;     more, or less..<br>
&gt;     &gt;<br>
&gt;     &gt; To be fair I actually agree that it&#39;s very likely that C2 can<br>
&gt;     make any performance penalty disappear.. that&#39;s totally possible,<br>
&gt;     although it&#39;s unlikely to be faster than just reading the field<br>
&gt;     (assuming we don&#39;t need to do branching because of null-checks but<br>
&gt;     C2 can optimise that as well).<br>
&gt;     &gt; Still this requires the code to be optimised by JIT first, so it<br>
&gt;     won&#39;t prevent us from creating a gazillion of instances if we<br>
&gt;     abuse its usage irresponsibly. Fighting internal NPEs is a matter<br>
&gt;     of writing better code; I&#39;m not against some &quot;Optional&quot; being<br>
&gt;     strategically placed but I believe it&#39;s much nicer for most<br>
&gt;     internal code to just avoid null, use &quot;final&quot;, and initialize<br>
&gt;     things aggressively.<br>
&gt;     &gt;<br>
&gt;     &gt; Sure use Optional where it makes sense, probably most on APIs<br>
&gt;     and SPIs, but please don&#39;t go overboard with it in internals.<br>
&gt;     That&#39;s all I said in the original debate.<br>
&gt;     &gt;<br>
&gt;     &gt; In case you want to benchmark the impact of Optional make a JMH<br>
&gt;     based microbenchmark - that&#39;s interesting to see what C2 is<br>
&gt;     capable of - but even so that&#39;s not going to tell you much on the<br>
&gt;     impact it would have to patch thousands of code all around<br>
&gt;     Infinispan. And it will need some peer review before it can tell<br>
&gt;     you anything at all ;)<br>
&gt;     &gt;<br>
&gt;     &gt; It&#39;s actually a very challenging topic, as we produce libraries<br>
&gt;     meant for &quot;anyone to use&quot; and don&#39;t get to set the hardware<br>
&gt;     specification requirements it&#39;s hard to predict if we should<br>
&gt;     optimise the system for this/that resource consumption. Some<br>
&gt;     people will have plenty of CPU and have problems with us needing<br>
&gt;     too much memory, some others will have the opposite.. the real<br>
&gt;     challenge is in making internals &quot;elastic&quot; to such factors and<br>
&gt;     adaptable without making it too hard to tune.<br>
&gt;     &gt;<br>
&gt;     &gt; Thanks,<br>
&gt;     &gt; Sanne<br>
&gt;     &gt;<br>
&gt;     &gt;<br>
&gt;     &gt;<br>
&gt;     &gt; On 18 May 2017 at 12:30, Sebastian Laskawiec<br>
&gt;     &lt;<a href="mailto:slaskawi@redhat.com" target="_blank">slaskawi@redhat.com</a> &lt;mailto:<a href="mailto:slaskawi@redhat.com" target="_blank">slaskawi@redhat.com</a>&gt;&gt; wrote:<br>
&gt;     &gt; Hey!<br>
&gt;     &gt;<br>
&gt;     &gt; In our past we had a couple of discussions about whether we<br>
&gt;     should or should not use Optionals [1][2]. The main argument<br>
&gt;     against it was performance.<br>
&gt;     &gt;<br>
&gt;     &gt; On one hand we risk additional object allocation (the Optional<br>
&gt;     itself) and wrong inlining decisions taken by C2 compiler [3]. On<br>
&gt;     the other hand we all probably &quot;feel&quot; that both of those things<br>
&gt;     shouldn&#39;t be a problem and should be optimized by C2. Another<br>
&gt;     argument was the Optional&#39;s doesn&#39;t give us anything but as I<br>
&gt;     checked, we introduced nearly 80 NullPointerException bugs in two<br>
&gt;     years [4]. So we might consider Optional as a way of fighting<br>
&gt;     those things. The final argument that I&#39;ve seen was about lack of<br>
&gt;     higher order functions which is simply not true since we have<br>
&gt;     #map, #filter and #flatmap functions. You can do pretty amazing<br>
&gt;     things with this.<br>
&gt;     &gt;<br>
&gt;     &gt; I decided to check the performance when refactoring REST<br>
&gt;     interface. I created a PR with Optionals [5], ran performance<br>
&gt;     tests, removed all Optionals and reran tests. You will be<br>
&gt;     surprised by the results [6]:<br>
&gt;     &gt;<br>
&gt;     &gt; Test case<br>
&gt;     &gt; With Optionals [%]    Without Optionals<br>
&gt;     &gt; Run 1 Run 2   Avg     Run 1   Run 2   Avg<br>
&gt;     &gt; Non-TX reads 10 threads<br>
&gt;     &gt; Throughput    32.54   32.87   32.71   31.74   34.04  32.89<br>
&gt;     &gt; Response time -24.12  -24.63  -24.38  -24.37  -25.69 -25.03<br>
&gt;     &gt; Non-TX reads 100 threads<br>
&gt;     &gt; Throughput    6.48    -12.79  -3.16   -7.06   -6.14  -6.60<br>
&gt;     &gt; Response time -6.15   14.93   4.39    7.88    6.49 7.19<br>
&gt;     &gt; Non-TX writes 10 threads<br>
&gt;     &gt; Throughput    9.21    7.60    8.41    4.66    7.15 5.91<br>
&gt;     &gt; Response time -8.92   -7.11   -8.02   -5.29   -6.93  -6.11<br>
&gt;     &gt; Non-TX writes 100 threads<br>
&gt;     &gt; Throughput    2.53    1.65    2.09    -1.16   4.67 1.76<br>
&gt;     &gt; Response time -2.13   -1.79   -1.96   0.91    -4.67  -1.88<br>
&gt;     &gt;<br>
&gt;     &gt; I also created JMH + Flight Recorder tests and again, the<br>
&gt;     results showed no evidence of slow down caused by Optionals [7].<br>
&gt;     &gt;<br>
&gt;     &gt; Now please take those results with a grain of salt since they<br>
&gt;     tend to drift by a factor of +/-5% (sometimes even more). But it&#39;s<br>
&gt;     very clear the performance results are very similar if not the same.<br>
&gt;     &gt;<br>
&gt;     &gt; Having those numbers at hand, do we want to have Optionals in<br>
&gt;     Infinispan codebase or not? And if not, let&#39;s state it very<br>
&gt;     clearly (and write it into contributing guide), it&#39;s because we<br>
&gt;     don&#39;t like them. Not because of performance.<br>
&gt;     &gt;<br>
&gt;     &gt; Thanks,<br>
&gt;     &gt; Sebastian<br>
&gt;     &gt;<br>
&gt;     &gt; [1]<br>
&gt;     <a href="http://lists.jboss.org/pipermail/infinispan-dev/2017-March/017370.html" rel="noreferrer" target="_blank">http://lists.jboss.org/pipermail/infinispan-dev/2017-March/017370.html</a><br>
&gt;     &gt; [2]<br>
&gt;     <a href="http://lists.jboss.org/pipermail/infinispan-dev/2016-August/016796.html" rel="noreferrer" target="_blank">http://lists.jboss.org/pipermail/infinispan-dev/2016-August/016796.html</a><br>
&gt;     &gt; [3]<br>
&gt;     <a href="http://vanillajava.blogspot.ro/2015/01/java-lambdas-and-low-latency.html" rel="noreferrer" target="_blank">http://vanillajava.blogspot.ro/2015/01/java-lambdas-and-low-latency.html</a><br>
&gt;     &gt; [4]<br>
&gt;     <a href="https://issues.jboss.org/issues/?jql=project%20%3D%20ISPN%20AND%20issuetype%20%3D%20Bug%20AND%20text%20%7E%20%22NullPointerException%22%20AND%20created%20%3E%3D%202015-04-27%20AND%20created%20%3C%3D%202017-04-27" rel="noreferrer" target="_blank">https://issues.jboss.org/issues/?jql=project%20%3D%20ISPN%20AND%20issuetype%20%3D%20Bug%20AND%20text%20%7E%20%22NullPointerException%22%20AND%20created%20%3E%3D%202015-04-27%20AND%20created%20%3C%3D%202017-04-27</a><br>
&gt;     &gt; [5] <a href="https://github.com/infinispan/infinispan/pull/5094" rel="noreferrer" target="_blank">https://github.com/infinispan/infinispan/pull/5094</a><br>
&gt;     &gt; [6]<br>
&gt;     <a href="https://docs.google.com/a/redhat.com/spreadsheets/d/1oep6Was0FfvHdqBCwpCFIqcPfJZ5-5_YYUqlRtUxEkM/edit?usp=sharing" rel="noreferrer" target="_blank">https://docs.google.com/a/redhat.com/spreadsheets/d/1oep6Was0FfvHdqBCwpCFIqcPfJZ5-5_YYUqlRtUxEkM/edit?usp=sharing</a><br>
&gt;     &gt; [7]<br>
&gt;     <a href="https://github.com/infinispan/infinispan/pull/5094#issuecomment-296970673" rel="noreferrer" target="_blank">https://github.com/infinispan/infinispan/pull/5094#issuecomment-296970673</a><br>
&gt;     &gt; --<br>
&gt;     &gt; SEBASTIAN ŁASKAWIEC<br>
&gt;     &gt; INFINISPAN DEVELOPER<br>
&gt;     &gt; Red Hat EMEA<br>
&gt;     &gt;<br>
&gt;     &gt;<br>
&gt;     &gt; _______________________________________________<br>
&gt;     &gt; infinispan-dev mailing list<br>
&gt;     &gt; <a href="mailto:infinispan-dev@lists.jboss.org" target="_blank">infinispan-dev@lists.jboss.org</a><br>
&gt;     &lt;mailto:<a href="mailto:infinispan-dev@lists.jboss.org" target="_blank">infinispan-dev@lists.jboss.org</a>&gt;<br>
&gt;     &gt; <a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a><br>
&gt;     &gt;<br>
&gt;     &gt; _______________________________________________<br>
&gt;     &gt; infinispan-dev mailing list<br>
&gt;     &gt; <a href="mailto:infinispan-dev@lists.jboss.org" target="_blank">infinispan-dev@lists.jboss.org</a><br>
&gt;     &lt;mailto:<a href="mailto:infinispan-dev@lists.jboss.org" target="_blank">infinispan-dev@lists.jboss.org</a>&gt;<br>
&gt;     &gt; <a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a><br>
&gt;<br>
&gt;<br>
&gt;     _______________________________________________<br>
&gt;     infinispan-dev mailing list<br>
&gt;     <a href="mailto:infinispan-dev@lists.jboss.org" target="_blank">infinispan-dev@lists.jboss.org</a> &lt;mailto:<a href="mailto:infinispan-dev@lists.jboss.org" target="_blank">infinispan-dev@lists.jboss.org</a>&gt;<br>
&gt;     <a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a><br>
&gt;<br>
&gt; --<br>
&gt;<br>
&gt; SEBASTIANŁASKAWIEC<br>
&gt;<br>
&gt; INFINISPAN DEVELOPER<br>
&gt;<br>
&gt; Red HatEMEA &lt;<a href="https://www.redhat.com/" rel="noreferrer" target="_blank">https://www.redhat.com/</a>&gt;<br>
&gt;<br>
&gt; &lt;<a href="https://red.ht/sig" rel="noreferrer" target="_blank">https://red.ht/sig</a>&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; infinispan-dev mailing list<br>
&gt; <a href="mailto:infinispan-dev@lists.jboss.org" target="_blank">infinispan-dev@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a><br>
<br>
--<br>
Bela Ban, JGroups lead (<a href="http://www.jgroups.org" rel="noreferrer" target="_blank">http://www.jgroups.org</a>)<br>
<br>
_______________________________________________<br>
infinispan-dev mailing list<br>
<a href="mailto:infinispan-dev@lists.jboss.org" target="_blank">infinispan-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a></blockquote></div></div></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr"><p class="inbox-inbox-fullname-container" style="box-sizing:border-box;color:rgb(0,0,0);font-family:overpass,sans-serif;font-weight:bold;margin:0px;padding:0px;font-size:14px;text-transform:uppercase"><span class="inbox-inbox-firstname-container" style="box-sizing:border-box">SEBASTIAN</span><span class="inbox-inbox-Apple-converted-space"> </span><span class="inbox-inbox-lastname-container" style="box-sizing:border-box">ŁASKAWIEC</span></p><p class="inbox-inbox-position-container" style="box-sizing:border-box;color:rgb(0,0,0);font-family:overpass,sans-serif;font-size:10px;margin:0px 0px 4px;text-transform:uppercase"><span class="inbox-inbox-position" style="box-sizing:border-box">INFINISPAN DEVELOPER</span></p><p class="inbox-inbox-legal-container" style="box-sizing:border-box;font-family:overpass,sans-serif;margin:0px;font-size:10px;color:rgb(153,153,153)"><a class="inbox-inbox-redhat-anchor" href="https://www.redhat.com/" target="_blank" style="box-sizing:border-box;color:rgb(0,136,206);margin:0px;text-decoration:none">Red Hat<span class="inbox-inbox-Apple-converted-space"> </span><span style="box-sizing:border-box">EMEA</span></a></p><table border="0" style="box-sizing:border-box;color:rgb(0,0,0);font-family:overpass,sans-serif;font-size:medium"><tbody style="box-sizing:border-box"><tr style="box-sizing:border-box"><td width="100px" style="box-sizing:border-box"><a href="https://red.ht/sig" style="box-sizing:border-box"><img width="90" height="auto" style="box-sizing: border-box;" src="https://www.redhat.com/files/brand/email/sig-redhat.png"></a></td></tr></tbody></table></div></div>