4 ms·
You don't have to look far at all to find such cases. Startup takes forever. It's not that there's a specific small operation that programs in both languages do
by scottlamb 6y ago
You don't have to look far at all to find such cases. Startup takes forever. It's not that there's a specific small operation that programs in both languages do and is O(log n) in C++ and O(n^2) in Java. It's more that the Java programs do work that is unthinkable with C++. They run an optimizing compiler (once they decide its worthwhile on a given function). That's not something C++ programs do. [1] Until that happens, they may be running completely unoptimized interpreted code. They might go through the whole thing again if they fill their perm gen (or whatever it's called) and evict the optimized version of the code. They run a garbage collector which sometimes stops the world. Your tiny function might have to wait for gigabytes of heap to be scanned.
Over sufficiently long runs, throughput is easily within the factor of 2 you mentioned. But over short timescales, thousands of times slower is completely plausible. Some C++ CLI application might run in 5 ms where the equivalent Java program takes 5 seconds.
IIRC there was some article recently challenging the assumption that Java programs commonly reach the optimized steady state at all. I can't find it though.
[1] Except V8 of course on the user-supplied JavaScript. I'd call that quite different than optimizing all Chrome's own code.
- lmm 6y agoSorry, I had a longer reply to your previous message that I lost somehow. In the context of something like Chrome that's already willing to implement a custom process model, I don't think that there are business requirements where that kind of large overhead is unavoidable. Running an individual unix-style JVM process can indeed perform very poorly on the default settings. But that's not the only way to build a web browser.
- jolux 6y agoIt’s probably doable but I don’t know with what kind of performance envelope. Java famously has very high runtime costs in pathological cases, and it’s very easy to shoot oneself in the foot. I completely agree that memory safety is more important, but it’s not like they wrote a new rendering engine from whole cloth, they used WebKit.