r/java • • Jun 10 '24

[deleted by user]

[removed]

612 Upvotes

594 comments sorted by

View all comments

Show parent comment

2

u/ai_jarvis Jun 10 '24

So I have recently found one space where Java is demonstratively slower than something else (Go Lang). When mapping a file for realtime search, GO is faster and smaller in memory than Java. An extreme edge case, likely something you won't ever need to deal with unless you are attempting to do real time searches on datasets in excess of 100+ million "rows" at high TPS with ultra low latency.

Context: lookups where millisecond to sub-millisecond latencies have actual impact.

2

u/thecodeboost Jun 11 '24

This is almost certainly an apples and oranges issue. Any I/O limited workload should have no measurable performance benefits on the language side since the vast majority of time is spent on I/O. I'm fluent in both and I can't think of a reason why a Golang implementation would be faster than Java in any measurable way. Memory consumption is generally lower in Golang of course but that's a win at the expense of more fine grained memory management by developers.

2

u/koflerdavid Jun 11 '24

Did you use Java NIO's API for memory mapping files or an FFI?

3

u/ai_jarvis Jun 11 '24

We didn't do an FFI, just the NIO API and the file took ~19 seconds to map whereas the same file was done in less than 2 seconds with GO.

Java used 2.1x file size of memory vs GO which was just 4% larger than the file.

Look up times were faster too.

3

u/koflerdavid Jun 12 '24

This sounds like there are lots of optimization opportunities in that API. Although part of the problem might be that any data has to be copied to the heap to be accessible for Java code. ByteBuffers can provide limited access to off-heap memory, but retrieving data through these is equivalent to copying data around.