
Java Code Challenge: Shortest Code and Lowest Latency - minborg
http://minborgsjavapot.blogspot.com/2018/11/shortest-code-and-lowest-latency.html
======
joshstrange
Wow the CTO of Speedment posted a challenge and the "winner" used Speedment?
Who would have thought... Also when it comes to code golfing this is a BS
experiment. If you don't count the library LOC then I can just create
SpeedmentSucksLib that literally just uses the code that "won" and now my
solution is 1 line:

    
    
        SpeedmentSucksLib.doTheThing()
    

Also we just are going to ignore import/main class LOC's? Really this is a
terrible article and it leaves a bad taste in my mouth re: speedment.

~~~
minborg
Your proposed "solution" is hardly a general solution. The winner used a
java.util.stream.Stream class which is a standard Java class. The rules
([https://www.speedment.com/code-one/](https://www.speedment.com/code-one/))
stated that import/main class rows were not counted. But even if they did,
they would impact any solution about the same.

------
stevoo
I was trying to understand how this was so much efficient and how did he
manage to generate this will so little code. Where was his query retrievals ?
Where did those classes magically appear. How did he retrieve the data so
fast.

Then i read the first line, he is the CTO of Speedment.

So he had to add maven dependency to his project generate ton of code, to
create his objects, retrieve all them and do the computation in the Speedment
optimized functions.

So with his goal to use as less code as possible, he had to add third party
library that added tons of code that he did not count in the lines of code
that was written.

Seems a bit like self promotion and unfair to be honest.

------
tralarpa
There is something I don't understand. They say that the winner used
Speedment. If I understood the example on github correctly, Speedment also
uses SQL internally. So, why is the same query over JDBC so much slower than
with Speedment?

Could it be that Speedment avoids the nested select and does the calculations
of the statistics by itself? Would that mean that I should use Speedment only
when the result set is very small? How would the performance look like if the
task were to calculate the average film length of 10000 films from a table of
100,000 films?

~~~
minborg
Speedment uses in-JVM-memory technology so, once the tables are moved into the
JVM, streams are served using content and indexes directly from off-heap RAM.

------
sk5t
This article is probably not worth reading. There's little point in comparing
an in-memory Java stream-based approach against JDBC--without even the
intellectual honesty to use something like in-memory SQLite.

~~~
minborg
It would be interesting to do a benchmark between Speedment and in-memory
SQLite. I will put that on my list. Thanks for the tip.

------
norswap
Does the winning solution read from a database? Otherwise this is an apple-to-
oranges comparison. If it does, the connection code certainly isn't shown.

~~~
minborg
It reads from memory, not the database. It is true that querying a database
vs. using in-JVM-memory snapshots are not the same. They both have different
properties. The case at hand was to analyze immutable data where working with
snapshots makes sense. If, on the other hand, the case was to work with data
in a highly transactional application, then snapshots make little or no sense.

------
ynniv
I like the idea, but when the winner is calling a 3rd party library it becomes
meaningless marketing.

------
minborg
Hi all! Nice to see your engagement. I understand your concern about self-
promotion but the contest was open and contestants were free to choose any
tool, not just Speedment.

I have contributed to open-source speedment stream ORM for many years and have
now added in-JVM-memory acceleration. I am still curious to see if your guys
can come up with something better.

Give it a real shoot using whatever you can think of. If you can beat it, I
promise to write another article about it. Sounds fair?

NB: Setup code adds about 5 extra lines, similar to other tools.

