TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Java JIT vs. Java AOT vs. Go for Small, Short-Lived Processes

175 pointsby robfigover 5 years ago

19 comments

robfigover 5 years ago
It&#x27;s hard to square these articles with the reality I see on the ground: our baseline memory usage for common types of Java service is 1 GB, vs 50 MB for Go. We do have a few mammoth servers at the top end in both languages though (e.g. 75 GB heaps)<p>The deploy JARs have 100+ MB of class files, so perhaps it&#x27;s a function of all the dependencies that you &quot;need&quot; for an enterprise Java program and not something more fundamental.<p>These blog posts also present AOT as if its just another option you can toggle, while my impression is that it&#x27;s incompatible with common Java libraries and requires swapping &#x2F; maintaining a parallel compiler in the build toolchain, configuring separate rules to build it AOT, etc. I don&#x27;t have actual experience with it though so I could be missing something.
评论 #21872541 未加载
评论 #21872620 未加载
评论 #21872750 未加载
评论 #21873600 未加载
评论 #21872418 未加载
评论 #21874190 未加载
评论 #21872499 未加载
评论 #21874456 未加载
评论 #21875072 未加载
评论 #21874047 未加载
评论 #21873331 未加载
评论 #21874213 未加载
评论 #21875307 未加载
评论 #21872725 未加载
评论 #21874922 未加载
评论 #21872724 未加载
correct_horseover 5 years ago
Go has no proper solution to garbage collector ballast, a hack which businesses you&#x27;ve heard of are using in the wild. see <a href="https:&#x2F;&#x2F;blog.twitch.tv&#x2F;en&#x2F;2019&#x2F;04&#x2F;10&#x2F;go-memory-ballast-how-i-learnt-to-stop-worrying-and-love-the-heap-26c2462549a2&#x2F;" rel="nofollow">https:&#x2F;&#x2F;blog.twitch.tv&#x2F;en&#x2F;2019&#x2F;04&#x2F;10&#x2F;go-memory-ballast-how-i...</a> and <a href="https:&#x2F;&#x2F;github.com&#x2F;golang&#x2F;go&#x2F;issues&#x2F;23044" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;golang&#x2F;go&#x2F;issues&#x2F;23044</a>. A golang team member&#x27;s reasons for not adding a minimum heap size include that it would require more testing each release, and that they might want to have a max heap size hint instead.<p>I posted a comment similar to this one recently, but it seems more relevant here.
评论 #21875008 未加载
ape4over 5 years ago
For a short lived Java process you can use the no-op garbage collector (ie don&#x27;t collect). <a href="http:&#x2F;&#x2F;openjdk.java.net&#x2F;jeps&#x2F;318" rel="nofollow">http:&#x2F;&#x2F;openjdk.java.net&#x2F;jeps&#x2F;318</a>
评论 #21873605 未加载
评论 #21872483 未加载
harikbover 5 years ago
When I was looking for my first car in early 90s, I knew nothing about cars or brands. One thing I noticed was that all the TV ads for most of the cars would say &quot;more room than a Camry&quot;. I knew what I needed to buy.<p>If Go doesn&#x27;t survive another decade, I would still be happy about what it triggered.
zestypingover 5 years ago
100 ms is nowhere near what I&#x27;d call &quot;negligible&quot; for a process that might only live a second or two!<p>python -c print &#x27;hello&#x27; starts up and shuts down an entire Python interpreter in less than 50 ms on my machine, whereas the equivalent Java program never takes less than 120 ms. That seems pretty sad for a language that&#x27;s had at least an order of magnitude more resources thrown at it.
评论 #21874056 未加载
评论 #21874615 未加载
评论 #21874320 未加载
mikeceover 5 years ago
I&#x27;m curious how Dart2Native would fare in this test, if it would be more or less the same as Go or if it would be more efficient.
评论 #21874151 未加载
评论 #21874338 未加载
karmakazeover 5 years ago
I&#x27;ve run small services built with Java, Go and Crystal to achieve good startup and throughput performance while minimizing memory usage. My experience with Crystal is limited but has been positive thus far.<p>The sweet spot for me is using Java with OpenJ9 which has very fast startup time while sacrificing only a bit of top-end throughput.<p>I would only choose AOT if packaging&#x2F;deployment were issues with the JIT approach. In the case of Go, AOT is practically free but I prefer not being limited to array&#x2F;slice, map, and channel generics.
CountHackulusover 5 years ago
I&#x27;d kill for a comparison with the IBM J9 AOT flag. It essentially just caches jitted code for startup. Also if startup time is super important than you can try -Xquickstart.
skywhopperover 5 years ago
Interesting numbers. I have been out of the Java world for a few years and I’m unfamiliar with GraalVM but I’m curious how compatible it is with Oracle Java or OpenJDK.<p>Of course for small scale stuff like a QuickSort implementation, JVM starts are fast-ish, but for a nontrivial service, library load times during boot can balloon quickly depending on your build discipline.
评论 #21872523 未加载
srequeover 5 years ago
This article reiterates the belief that jvm start-up time is slow is somewhat a myth. When. I measured it years ago, I found jvm start-up time to be roughly equivalent to node.js.<p>What makes start-up time bad in any interpreted language, including Java, python, and JavaScript, is code-loading time. This time is 0(n), where n is the total size of your app, including transitive dependencies. It takes time to load, parse, and validate non-native code. This time far dwarfs any vm start-up time.<p>As an experiment, write a hello world node.js app and time it&#x27;s execution. Then add an import statement on the aws sdk. Don&#x27;t actually use it. Just import it! When I last measured it, this caused start-up time to go from 30 Ms to something like 300 Ms. The extra time mostly comes from loading code.<p>For a native app, the binary itself just gets mmapped into memory. Shared library loading is more expensive, but not much, and way less than loading source code or byte code.<p>The tldr is if you want a fast starting non-native app, you have to shrink the transitive dependency closure your app loads to do it&#x27;s job. This is easy for toy benchmark apps but can be harder for real apps. It also goes against the philosophy of most devs to rely on third party libraries for everything. For instance, If you care about start-up time, it may be worth re implementing that function you&#x27;d normally get from guava or apache commons. You can alternatively use a tool like proguard to shrink your dependency closure.
xvilkaover 5 years ago
It would be nice to have some automated tools to convert from Java to Go or Rust. Something like c2rust [1], but for Java. There exist[2] some kind of automation, buts it&#x27;s too basic to be practical.<p>[1] <a href="https:&#x2F;&#x2F;GitHub.com&#x2F;immunant&#x2F;c2rust" rel="nofollow">https:&#x2F;&#x2F;GitHub.com&#x2F;immunant&#x2F;c2rust</a><p>[2] <a href="https:&#x2F;&#x2F;github.com&#x2F;aschoerk&#x2F;converter-page" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;aschoerk&#x2F;converter-page</a>
gokover 5 years ago
&quot;3 Bad Tools for a Job, which is least bad?&quot;
评论 #21876474 未加载
AtlasBarfedover 5 years ago
Why can&#x27;t the JVM preload on startup the majority of the core runtime as a shared library architecture in a sort of super-permanent generation, and then the JVMs piggyback on that?<p>I remember solaris boxes had little of the startup cost and someone told me they preloaded the java runtime.
评论 #21892129 未加载
rijojaover 5 years ago
Wouldn&#x27;t the JIT:ed code be optimized for the specific CPU, whereas the AOT perhaps can not make use of certain instructions? Also, when making a comparison off the different models one must keep in mind that the software that processes the code have different characteristics.
评论 #21875440 未加载
评论 #21874715 未加载
评论 #21875152 未加载
评论 #21875652 未加载
评论 #21874541 未加载
e12eover 5 years ago
Interesting write-up - would be nice to see not just the quicksort code, but the harness&#x2F;scripts used for benchmarking. As far as I can tell it&#x27;s not included?
haolezover 5 years ago
I wonder if AOT would speed up Groovy as well. My intuition is that it doesn&#x27;t matter, since the runtime will get bundled and execution time will be the same.
评论 #21874289 未加载
michaelcampbellover 5 years ago
Since the article is about &quot;short lived processes&quot;, I&#x27;m having a hard time caring about the memory use as a first order issue. &lt;shrug&gt;
评论 #21873191 未加载
mister_hnover 5 years ago
The question is: if you compile Java to native code, what&#x27;s the purpose of using Java instead of Go or Rust or C++?
评论 #21874702 未加载
评论 #21874371 未加载
评论 #21874923 未加载
ddtaylorover 5 years ago
For anyone looking to avoid attacks because of no SSL: <a href="https:&#x2F;&#x2F;archive.is&#x2F;Rzdko" rel="nofollow">https:&#x2F;&#x2F;archive.is&#x2F;Rzdko</a>