<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nikita Salnikov-Tarnovski on Medium]]></title>
        <description><![CDATA[Stories by Nikita Salnikov-Tarnovski on Medium]]></description>
        <link>https://medium.com/@nikem?source=rss-5c8bf38c9778------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*QAZ9vpd-gGRIBMVyTjcr9Q.jpeg</url>
            <title>Stories by Nikita Salnikov-Tarnovski on Medium</title>
            <link>https://medium.com/@nikem?source=rss-5c8bf38c9778------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 12:23:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nikem/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[First GraalVM in Plumbr]]></title>
            <link>https://medium.com/@nikem/first-graalvm-in-plumbr-8ae152566de2?source=rss-5c8bf38c9778------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ae152566de2</guid>
            <category><![CDATA[graalvm]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Nikita Salnikov-Tarnovski]]></dc:creator>
            <pubDate>Tue, 09 Jul 2019 07:35:11 GMT</pubDate>
            <atom:updated>2019-07-09T07:42:24.287Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a quick report of my experimentation with GraalVM JIT compiler. I have no explanation of the resulting numbers, but they were good enough for me to start using GraalVM JIT in one of our internal jobs.</p><p>The job in question is a batch process, which reads a lot of data from Kafka, some of it binary, some of it JSON. It parses that data, does a lot of manipulation with objects in memory. Some database is also involved. In the end it encodes it back to JSON and writes to files on disk. Technologies used are <a href="https://bell-sw.com/pages/java-11.0.3/">Liberica JDK11</a>, Spring Boot 2.1, Jackson, Kafka, MySQL.</p><p>I have run this batch job on the same dataset 3 times in a row. One is a baseline, without any modifications to our usual process.</p><p>Second one with <a href="https://openjdk.java.net/jeps/317">GraalVM CE JIT</a> which can be used on any OpenJDK-derived JVM by adding two options to JVM : -XX:+UnlockExperimentalVMOptions -XX:+UseJVMCICompiler</p><p>Third run was with <a href="https://www.oracle.com/technetwork/graalvm/downloads/index.html">GraalVM EE</a>, which you can use freely in development and experiments, but you need a separate license to use it in production.</p><p>The metric that we are interested in case of any batch job is its run duration:</p><ul><li>Baseline: <strong>5h02m</strong></li><li>GraalVM CE: <strong>4h33m</strong></li><li>GraalVM EE: <strong>3h57m</strong></li></ul><p>As I said, I have no explanation why exactly GraalVM JIT gave such a nice boost in performance. Nevertheless, I have switched our periodic execution of this batch job to use GraalVM CE JIT compiler. Very good performance improvement just by adding 2 options to your JVM :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ae152566de2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Some more about Spring Cache]]></title>
            <link>https://medium.com/@nikem/some-more-about-spring-cache-c6e7f60c5d1d?source=rss-5c8bf38c9778------2</link>
            <guid isPermaLink="false">https://medium.com/p/c6e7f60c5d1d</guid>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Nikita Salnikov-Tarnovski]]></dc:creator>
            <pubDate>Sun, 31 Mar 2019 12:54:12 GMT</pubDate>
            <atom:updated>2019-03-31T12:54:12.255Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a follow up to my last story <a href="https://medium.com/@nikem/is-spring-cache-abstraction-fast-enough-for-you-a6a5ea1542a9">“Is Spring Cache abstraction fast enough for you?”</a>, in which I would like to briefly talk about the importance of knowing your tools.</p><p>Take a look at the following two methods:</p><pre>@Cacheable(value = <strong>&quot;time&quot;</strong>, key = <strong>&quot;#p0.concat(#p1)&quot;</strong>)<br><strong>public long </strong>annotationWithSpel(String dummy1, String dummy2) {<br>  <strong>return </strong>System.<em>currentTimeMillis</em>();<br>}</pre><pre>@Cacheable(value = <strong>&quot;time&quot;</strong>)<br><strong>public long </strong>annotationBased(String dummy1, String dummy2) {<br>  <strong>return </strong>System.<em>currentTimeMillis</em>();<br>}</pre><p>Here we have 2 similar methods annotated with @Cacheable annotation from Spring Cache. First of them provides an expression written in <a href="https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#expressions">Spring Expression Language</a> to configure how to calculate cache key using method parameters. The second relies on Spring’s default behaviour which is “<em>all method parameters are considered as a key</em>”. So both methods from above actually result in <strong>exactly the same external behaviour</strong>.</p><p>But let us measure their performance:</p><pre>Benchmark                       Mode  Cnt     Score    Error  Units</pre><pre>CacheBenchmark.annotationBased  avgt    5   271.975 ± 11.586  ns/op</pre><pre>CacheBenchmark.spel             avgt    5  1196.744 ± 93.765  ns/op</pre><pre>CacheBenchmark.manual           avgt    5    16.325 ±  0.856  ns/op</pre><pre>CacheBenchmark.nocache          avgt    5    40.142 ±  4.012  ns/op</pre><p>Wow, the method with manually configured cache key runs about 4.4 times <strong>slower</strong>! Which is quite expected, if you think about it. Spring has to parse and evaluate some potentially arbitrary complex expression.</p><p>Why am I writing this story? Because I have found several cases in our own codebase where we have manually configured cache keys to have exactly the same behaviour as Spring Cache would provide us by default. Thus sacrificing performance for absolutely zero benefit. So do yourself a favour, review your code base and remove useless code :) Your code will be simpler and faster. Win-win!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c6e7f60c5d1d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Is Spring Cache abstraction fast enough for you?]]></title>
            <link>https://medium.com/@nikem/is-spring-cache-abstraction-fast-enough-for-you-a6a5ea1542a9?source=rss-5c8bf38c9778------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6a5ea1542a9</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[performance]]></category>
            <dc:creator><![CDATA[Nikita Salnikov-Tarnovski]]></dc:creator>
            <pubDate>Tue, 29 Jan 2019 07:50:10 GMT</pubDate>
            <atom:updated>2019-01-29T07:50:10.879Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently I have spent most of my time tuning the performance of one particular <a href="http://plumbr.io">Plumbr</a> codebase. It is quite a tight loop, reading data from Kafka, performing several computations and then writing data to a file. After several rounds of optimisations an unexpected code path started appearing in profiler output.The method in question was unexpected in the profile because it was already optimised :) At the beginning it went to DB asking for some relatively stable data. As it is clearly suboptimal, this method’s invocation was wrapped in a cache using <a href="https://docs.spring.io/spring/docs/5.1.4.RELEASE/spring-framework-reference/integration.html#cache">Spring Cache</a>. Thus it was a surprise seeing it contributing the substantial portion to the tight loop I was optimising. So I started digging and this blog post was born.</p><p>Let us take a look at minimal example: <a href="https://github.com/iNikem/spring-cache-jmh">https://github.com/iNikem/spring-cache-jmh</a>. We have <a href="https://github.com/iNikem/spring-cache-jmh/blob/97c289a68bda88c4f50dc50d37257747daa14a38/src/main/java/eu/plumbr/cache/CacheApplication.java#L33">a trivial method there</a>:</p><pre>@Cacheable(<strong>&quot;time&quot;</strong>)<br><strong>public long </strong>annotationBased(String dummy) {<br>  <strong>return </strong>System.<em>currentTimeMillis</em>();<br>}</pre><p>It is doing some work, which in here is just asking for a current time, and it is annotated with Spring’s @Cacheable annotation. This will result in Spring wrapping this method in a proxy and caching the result of method invocation using method’s input parameters as a key cache. Very straightforward and convenient optimisation: you see a slow method, slam one annotation on it, configure your cache provider ( ehcache.xml in my case) and you can pat yourself on the back.</p><p>Compare it with the same end-result but <a href="https://github.com/iNikem/spring-cache-jmh/blob/97c289a68bda88c4f50dc50d37257747daa14a38/src/main/java/eu/plumbr/cache/CacheApplication.java#L37">using cache manually</a>:</p><pre><strong>public long </strong>manual(String dummy) {<br>  Cache.ValueWrapper valueWrapper = <strong>cache</strong>.get(dummy);<br>  <strong>long </strong>result;<br>  <strong>if </strong>(valueWrapper == <strong>null</strong>) {<br>    result = System.<em>currentTimeMillis</em>();<br>    <strong>cache</strong>.put(dummy, result);<br>  } <strong>else </strong>{<br>    result = (<strong>long</strong>) valueWrapper.get();<br>  }<br>  <strong>return </strong>result;<br>}</pre><p>Much more going on, actual useful work is almost lost in accidental complexity of infrastructure-related boilerplate. Why should anyone prefer manual work to Spring’s magic? The answer lies in this <a href="https://openjdk.java.net/projects/code-tools/jmh/">JMH</a> <a href="https://github.com/iNikem/spring-cache-jmh/blob/master/src/jmh/java/eu/plumbr/cache/CacheBenchmark.java">benchmark</a> and its results:</p><pre>Benchmark                       Mode  Cnt    Score    Error  Units</pre><pre>CacheBenchmark.annotationBased  avgt    5  245.960 ± 27.749  ns/op</pre><pre>CacheBenchmark.manual           avgt    5   16.696 ±  0.496  ns/op</pre><pre>CacheBenchmark.nocache          avgt    5   44.586 ±  9.091  ns/op</pre><p>As you can see, a custom solution for the specific problem runs 15 times faster than general purpose one. That does not mean “Spring is slow!”, it does mean “Spring is doing much more work to support the wide range of general-purpose use-cases”. Note, that we still speak about several hundreds of <em>nanoseconds! </em>It should be negligible time in most scenarios! But in rare cases, when your <em>actual profiling data</em> shows that Spring Cache abstraction adds too much of overhead, don’t be afraid to make your hands dirty and roll out custom solution, specifically tailored to your needs.</p><p>And the last note about the nocache line from above. In this particular case the actual work our method does is so small, that adding caching actually slows it down. A perfect, albeit synthetical, example of premature optimisation: don’t optimise anything until the actual measurement proves the need for this. And then don’t forget to measure again after the optimisation :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6a5ea1542a9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Groovy CompileStatic]]></title>
            <link>https://medium.com/@nikem/groovy-compilestatic-461146a534ec?source=rss-5c8bf38c9778------2</link>
            <guid isPermaLink="false">https://medium.com/p/461146a534ec</guid>
            <category><![CDATA[groovy]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Nikita Salnikov-Tarnovski]]></dc:creator>
            <pubDate>Sun, 02 Dec 2018 14:52:43 GMT</pubDate>
            <atom:updated>2018-12-03T10:16:56.606Z</atom:updated>
            <content:encoded><![CDATA[<p>Groovy CompileStatic</p><p>During the recent chat with my friends I heard the opinion that “Groovy with @CompileStatic annotation does not differ from Java. No syntactic sugar, no metaprogramming. So it is as fast as Java”. As I disagreed with this opinion I went on providing some quite trivial examples which, in my opinion, refute that claim. The source code of them can be found here: <a href="https://github.com/iNikem/compilestatic">https://github.com/iNikem/compilestatic</a></p><p>Before we proceed: I don’t claim anything about the performance nor suitability of Groovy in general. This post is a tiny comparison between Groovy and Java in very specific examples with goal to show, that even with static compilation Groovy is not identical to Java.</p><p>So, first example is trivial <a href="https://github.com/iNikem/compilestatic/blob/master/src/jmh/java/eu/plumbr/ConstructorBench.java">object construction</a>. Just creating an instance of the empty class with default constructor. The benchmark results on my MBP are following</p><pre>ConstructorBench.initDynamicGroovy    avgt  5  5.205 ±  0.058  ns/op</pre><pre>ConstructorBench.initJava             avgt  5  2.827 ±  0.033  ns/op</pre><pre>ConstructorBench.initStaticGroovy     avgt  5  4.694 ±  0.042  ns/op</pre><p>In this case we can see that even when statically compiled object creation is much slower in Groovy than in Java. Comparing <a href="https://github.com/iNikem/compilestatic/tree/master/bytecodes/objectConstructor">the bytecode of generated</a> classes explain this somewhat. Below is the “pseudo-code” version of that bytecode:</p><pre><strong>public </strong>DynamicGroovy() {<br>  CallSite[] var1 = $getCallSiteArray();<br>  <strong>super</strong>();<br>  MetaClass var2 = <strong>this</strong>.$getStaticMetaClass();<br>  <strong>this</strong>.metaClass = var2;<br>}</pre><pre><strong>public </strong>StaticGroovy() {<br>  MetaClass var1 = <strong>this</strong>.$getStaticMetaClass();<br>  <strong>this</strong>.metaClass = var1;<br>}</pre><pre><strong>public </strong>MainJava() {<br>}</pre><p>This seems to strongly confirm my point: even with static compilation Groovy produces much bigger bytecode than Java, with obvious performance impact.</p><p>After presenting these results, I got an objection from my friend that object creation does not really matter and was pointed to this blog post comparing Groovy and Java performance on simple arithmetic operations: <a href="http://java-performance.info/static-code-compilation-groovy-2-0/">http://java-performance.info/static-code-compilation-groovy-2-0/</a>. Reimplementing this in JMH (<a href="https://github.com/iNikem/compilestatic/blob/master/src/jmh/java/eu/plumbr/CalculatorBench.java">here</a>) I got the following results:</p><pre>CalculatorBench.dynamicGroovy  avgt    5    10.597 ±  0.142  ns/op</pre><pre>CalculatorBench.javaCalculator avgt    5     5.019 ±  0.122  ns/op</pre><pre>CalculatorBench.staticGroovy   avgt    5     4.876 ±  0.043  ns/op</pre><p>These number confirm the original claim: the performance of Java code and of statically compiled Groovy are the same, with dynamic Groovy being noticeable slower.</p><p>At this moment I have remembered the actual case from my current project when replacing statically compiled Groovy code with pure Java gave us huge performance gains. The code in question was this:</p><pre>public long extractStart(long l1, long l2, long l3) { <br>  LongStream.of(l1, l2, l3)        <br>            .filter { it &gt; 0 }        <br>            .min()        <br>            .orElse(0)  <br>}</pre><p><a href="https://github.com/iNikem/compilestatic/blob/master/src/jmh/java/eu/plumbr/StreamBench.java">Benchmark</a> gave very peculiar results:</p><pre>StreamBench.dynamicGroovyStream    avgt  5   363.804 ±  5.850  ns/op</pre><pre>StreamBench.javaStream             avgt  5    36.692 ±  0.764  ns/op</pre><pre>StreamBench.staticGroovyStream     avgt  5  2341.419 ± 87.605  ns/op</pre><p>Java is the fastest, no surprises here. But statically compiled Groovy is 6 times <em>slower </em>than dynamic Groovy! I still have no idea how is this possible, but just documenting the results of the experiment for now.</p><p>In my opinion the main conclusion from this small friendly debate is the usual one: the correct answer is “it depends”. You cannot predict the performance of any code just by looking at it. If you care about the speed, you have to measure your particular code under the realistic load. The definition of “realistic” is 100% use-case specific.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=461146a534ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>