Hacker News new | ask | show | jobs
by vbezhenar 3033 days ago
Current software stacks are incredibly bloated. I recently wrote a simple Java web server. I took care no to use unnecessary memory, I didn't use a single library for it, yet it can't do even basic functions without OOM unless I'm giving it 16MB RAM for heap (and it eats even more for other things). So almost 20 MB RAM for hello world. And that's for relatively efficient VM. I guess, similar web server written with C would use around 20 KB RAM (and most of it for I/O buffers).
1 comments

That's such an unfair comparison, though (and really, with 8+ GB of RAM being the norm, 20 MB is still pretty svelte). Java has an entire virtual machine and runtime, whereas a C program is just a binary that gets loaded straight into memory.
Java theoretically taking a lot of care not to use excessive memory. It loads classes on demand, it compiles bytecode only when this path is really hot. I don't really see why it's necessary to use 16MB RAM. Golang has GC and doesn't that much memory. Lua has an entire virtual machine and runtime and doesn't use that much memory either. It's not a valid argument. I still believe that current JVM developers just don't care that much about memory consumption which is a valid decision, but I don't like it anyway. Not everyone has 8+GB of RAM. I have 256 MB VPS which runs quite a few of network services and has half of memory free, but I don't think that I could afford Java if I want to run something there, even if my load is tiny.
functionally and computationally, the tiny C program and the java monster would be doing the same thing....

So yes, they're comparable. Choosing inefficient ways to do things (in the case of Java) is not a way to escape comparison.

You can't say "wow, look how much smaller the C program is" and then ignore why it's so much smaller in the first place (no runtime, no garbage collection, etc.) If that's the case, then we should hand-roll assembly all the time because it's "smaller". You also can't just call Java inefficient because it produces larger programs or is "slower". It's all about choosing the right tool for the job.
Perhaps Java should have been designed to scale down and not require all that stuff when perfectly reasonable applications don't need them all the time.
Then those "perfectly reasonable" applications are free to eschew languages like Java. People do it all the time to great success. People also use Java to great success. But that's neither here nor there. My point is that it's unfair to call Java programs bloated when the extra space is necessary to support the runtime environment that makes Java Java. I'm not arguing the merits of such a thing (indeed, swap Java with literally any other language), I just want it to be clear that C and Java programs run differently, and both languages/runtimes, such as they are, were developed at different times and to serve different purposes, and therefore it's not correct to bemoan that Java programs are larger. That's like complaining that JavaScript doesn't give you direct memory access or that assembly doesn't have classes.