News for hackers. Stuff that matters.
Re:Kotlin's hidden costs – Benchmarks by richdougherty on Tuesday July 04, 2017 @06:12PM (#14698663)
Summary: most stuff is within 5-10% of Java. In performance sensitive code be careful of the spread operator and foreach on ranges which have higher costs.
Re:Kotlin's hidden costs – Benchmarks by dcow on Tuesday July 04, 2017 @07:07PM (#14698891)
Except the parts where Kotlin actually beats Java.
Re:Kotlin's hidden costs – Benchmarks by sk0g on Tuesday July 04, 2017 @10:22PM (#14699604)
It was still within 5-10%, just on the other end of the scale!
Re:Kotlin's hidden costs – Benchmarks by on_and_off on Wednesday July 05, 2017 @05:26AM (#14700979)
Are these results relevant though ?

Kotlin is also costly when it needs to create an object in order to pass a function (like in a non inlined higher order function). So I would expect a comparison of the number of allocations too.

From there it gets tricky because it really depends on the JVM you are running on in order to determine if this is going to generate enough pressure on the GC in order to have pauses, but that's a potential cost.

Also .. in the end the results are not that different while the 2 languages have very different capabilities. Delegates, higher-order functions, nullability, data classes, ... Kotlin has a lot to offer.

Re:Kotlin's hidden costs – Benchmarks by BurningFrog on Tuesday July 04, 2017 @10:09PM (#14699575)
5-10% is 3-6 months of Moore's Law.
Re:Kotlin's hidden costs – Benchmarks by nine_k on Wednesday July 05, 2017 @01:06AM (#14700072)
If it still held. "The free lunch is over" [1], and has been for years now.

[1]:http://www.gotw.ca/publications/concurrency-ddj.htm

Re:Kotlin's hidden costs – Benchmarks by jorgemf on Tuesday July 04, 2017 @09:37PM (#14699466)
If I recall correctly kotlin by default compiles to bytecode of Java 1.6. So o be afair comparison you should enable kotlin to compile to 1.8. as it is bytecode anyway I would expect very similar performance. But comparing 1.6 with 1.8 it is obvious 1.6 would be slower.
Re:Kotlin's hidden costs – Benchmarks by pjmlp on Wednesday July 05, 2017 @01:48AM (#14700188)
The bytecode differences between 1.6 and 1.8 bytecodes are mainly invokedynamic and methodhandles.

If Kotlin doesn't take advantage of them when targeting 1.8, the bytecode version won't do any difference.

Re:Kotlin's hidden costs – Benchmarks by jorgemf on Wednesday July 05, 2017 @08:59AM (#14702013)
My point is that kotlin by default targets 1.6. You need to specify to target 1.8 if you want to use it. So for me the experiment is broken. You should either compare java 1.6 with kotlin or set up kotlin to use 1.8 to compare with the same java version.
Re:Kotlin's hidden costs – Benchmarks by lgleason on Tuesday July 04, 2017 @06:25PM (#14698727)
Over time Kotlin's performance numbers will improve. For most applications though the small performance cost will be outweighed by the increased time to market and improved null handling.
Re:Kotlin's hidden costs – Benchmarks by matt4077 on Wednesday July 05, 2017 @12:58AM (#14700059)
Yeah, that's the go-to answer for slow runtimes...

In this case, "5-10% just isn't that much" may be the better excuse. Since Kotlin runs on the same jvm, it is a subset of Java, and therefore impossible for Kotlin to create code (and achieve speeds) that Java couldn't match.

In practice, Kotlin should asymptotically approach the performance of best-practice Java code, with possible performance improvements when it can correct unoptimised code, or implements new Java features without requiring any manual refactoring.

Re:Kotlin's hidden costs – Benchmarks by mobiletelephone on Wednesday July 05, 2017 @02:08AM (#14700252)
I agree with your conclusion, but it actually could be possible for kotlin to be faster than java for practical purposes, despite running on the JVM. For example, it might be more expressive, allowing the user to give the compiler more information for better optimizations. We see this when C++ is sometimes faster than C.
Re:Kotlin's hidden costs – Benchmarks by mike_hearn on Wednesday July 05, 2017 @03:35AM (#14700522)
Kotlin code can be and sometimes will be faster than the equivalent Java code because Kotlin does lambda inlining on the frontend and does not rely on the JVM to do so.

That probably helps a lot, because it takes significant machinery in the profiling and JIT compilers to automatically eliminate the overhead of higher-order functions and the JVM can't always do it due to a problem called "profile pollution". Kotlin pushes a bit of the thinking onto developers, albeit aided by type hints, and then does the inlining itself in many cases. Especially helpful on platforms with weaker JVMs like older Androids (the upcoming Android update appears to have improved ART so significantly that it's now a serious competitor to HotSpot).

Whilst the article doesn't show any difference in lambdas I wouldn't expect it to show up in micro-benchmarks like this one because the profile pollution problem wouldn't occur. In any real app it would show up though.

Also when Kotlin inlines on the frontend it can also use reified generics in a few cases.

Finally, Kotlin provides features that developers can use to write more efficient code, I'm thinking about how easy it makes lazyness in particular. Whilst you always can write equivalent code in Java, it takes more effort to do so, meaning developers probably won't always bother.

Re:Kotlin's hidden costs – Benchmarks by buremba on Wednesday July 05, 2017 @03:53AM (#14700606)
"Finally, Kotlin provides features that developers can use to write more efficient code, I'm thinking about how easy it makes lazyness in particular. Whilst you always can write equivalent code in Java, it takes more effort to do so, meaning developers probably won't always bother." -> Agreed!
Re:Kotlin's hidden costs – Benchmarks by elgenie on Wednesday July 05, 2017 @04:59AM (#14700873)
> Since Kotlin runs on the same jvm, it is a subset of Java, and therefore impossible for Kotlin to create code (and achieve speeds) that Java couldn't match.

This doesn't follow for several reasons. First, there are JVM bytecodes that Java doesn't use, so it would be more accurate to say that JVMLangX and Java both target subsets of the JVM. Second, higher order constructs could allow a JVMLangX-to-bytecode compiler to enforce checks at compile-time that would need to be done at runtime in Java.

Re:Kotlin's hidden costs – Benchmarks by hobo_mark on Tuesday July 04, 2017 @06:39PM (#14698778)
*decreased time to market

(I assume)

Re:Kotlin's hidden costs – Benchmarks by StreamBright on Tuesday July 04, 2017 @04:43PM (#14698162)
Excellent news, Kotlin is getting to be a real option on the JVM.
Re:Kotlin's hidden costs – Benchmarks by aplummer on Wednesday July 05, 2017 @01:05AM (#14700071)
I've never had to program so efficiently where this kind of thing would matter - only ever optimizing for readability and correctness in terms of bugs.

For people who do, do you enjoy performance optimization or does it get tedious?

Re:Kotlin's hidden costs – Benchmarks by sgift on Wednesday July 05, 2017 @03:34AM (#14700517)
Bit of both. I don't have to do it often and when you really need to press all the performance you can get out of some code it can be really maddening when there is no "obvious" reason. Quite often it is just an accumulation of many very small slowdowns which together are significant and then the measure, change, measure, change, measure ... loop can be very tedious. Sometimes, there are interesting things like changing the whole algorithm to something which performs better or reading up on bit-fiddling tricks which make some code remarkably faster (Hacker's Delight is not for the faint of the heart, but an interesting book nonetheless).
Re:Kotlin's hidden costs – Benchmarks by dm3 on Wednesday July 05, 2017 @03:43AM (#14700554)
As time goes on you keep accumulating these details in your head. Then you just think about the low-level stuff the same way you think about the higher-level stuff, like algorithmic complexity, code structure, etc.

It does get tedious if you need to get something out of the door fast, but have to shave off another 30% of processing time per unit of work. Honestly, I just try to partition the working set and throw more hardware at the problem in these scenarios.

Re:Kotlin's hidden costs – Benchmarks by Unknoob on Tuesday July 04, 2017 @04:21PM (#14698047)
Really wish the author labeled the axes. Took me way longer than I care to admit to figure out what the graphs meant.
Re:Kotlin's hidden costs – Benchmarks by chrisseaton on Tuesday July 04, 2017 @09:06PM (#14699347)
Isn't the relevant thing the relative value? What information are you getting from the absolute value which is the only thing you'd need a label for, given the author says taller is better? (We'd assume linear unless otherwise specified.)
Re:Kotlin's hidden costs – Benchmarks by jankotek on Wednesday July 05, 2017 @01:50AM (#14700193)
I write performance sensitive code in Kotlin. Most of those issues are common to Java8 and be worked around easily.
Re:Kotlin's hidden costs – Benchmarks by arrty88 on Wednesday July 05, 2017 @01:18PM (#14704289)
if it's still faster than javascript / nodeJS, we're in a good place.
Re:Kotlin's hidden costs – Benchmarks by time4tea on Tuesday July 04, 2017 @05:48PM (#14698522)
Clickbait.

It's the same.

Unless you care about a particular use case, when it isn't.

Measure, profile, refactor....

Re:Kotlin's hidden costs – Benchmarks by darylteo on Wednesday July 05, 2017 @02:26AM (#14700309)
The title is a response to another blog series called "Exploring Kotlin’s hidden costs". He is benchmarking the claims in those blog posts. Title Gore, perhaps. But not clickbait in this case.
Re:Kotlin's hidden costs – Benchmarks by chairmanwow on Tuesday July 04, 2017 @08:54PM (#14699297)
I felt similarly disenthused to realize the very small number of cases where Kotlin is slower.