5 ms·
I use Java constantly in my job and recently tried rewriting a math & memory heavy component in rust to see what performance gains there might be. Surprisingly
by ianlevesque 8y ago
I use Java constantly in my job and recently tried rewriting a math & memory heavy component in rust to see what performance gains there might be. Surprisingly (to me) the naive rust version was ~15% slower than Java. There’s probably room for more rust optimization but it was interesting that “efficient standalone binaries” doesn’t automatically mean faster too when competing with HotSpot.
- pjmlp 8y agoGoogle had a fast math library for Android, which got outperformed by ART JIT compiler and was eventually deprecated. https://developer.android.com/reference/android/util/FloatMath.html https://developer.android.com/reference/android/util/FloatMa...
- carlmr 8y agoI find where rust usually shines the most is if you do text processing. String allocations take time. In rust you can often avoid them and use things like cow to only allocate when you change something. That way often my text processing heavy scripts go twice the speed of a C++ version, and they're easier to write with Cargo, too. Compared to highly optimized Java and C# I could often get a quite naive rust implementation to be 10x faster. Naive rust means I didn't spend much time optimizing but I do use appropriate algorithms and to avoid unnecessary allocations.
- QuercusMax 8y agoMy experience working on writing image processing code in Java is that rewriting the slowest bits in C++ only gave about a 10% performance boost, and this was over a decade ago. Moving stuff to the GPU was vastly more effective than doing faster CPU work.
- alex_duf 8y agoWhen comparing speed on the JVM with speed with native languages, the only positive side you get from native binaries is cold start nowadays. For a webapp this doesn't matter, but as we're moving towards more cloud functions it start to make a lot of sense. That needs to be ponderated by the fact any real life application will have to access the network at bootstrap to load configuration and therefore your bottleneck will most likely be I/O.
- chrisweekly 8y ago> "ponderated" Huh! I have a fairly strong vocabulary and thought this might have been a made-up word -- but apparently it means "to weigh down or give substance to", which aligns with your intended point here. TIL
- alex_duf 8y agoSorry that's directly brought from French. English is my second language. I did a quick google search just to make sure it was correct but it's hard to gauge if a word that happen to be in the dictionary is also widely understood.
- vbezhenar 8y agoThe main performance gain would be memory consumption.
- mrath 8y agoI would except best performing Java code to be slower than best performing Rust code. But comparing general cases is not going to be simple.
- ahartmetz 8y agoI remember reading an article about Java performance many years ago. It had an example for Java being faster than C++ and it was maths on arrays / matrices. I guess that kind of code least trips up HotSpot optimizations, so it wins due to availability of runtime information and a really good implementation of certain parts. Though I doubt that Java usually wins against the Eigen C++ library. Eigen uses some template tricks to fold operations together (which can avoid intermediate storage and unlocks more types of restructuring optimizations) and uses SIMD extensively.
- pjmlp 8y agoProbably not, however Hotspot got some Intel help regarding auto-vectorization, including AVX support.
- deleted 8y ago[deleted]