Hacker News new | ask | show | jobs
by pluies_public 4244 days ago
That example will be horribly skewed by the JVM startup time, which is a known problem, but doesn't affect your program once it's started. It's pretty meaningless to compare programs that short, eg. scripts because noone sane would write them in either C++ or Java.
1 comments

If you were to reimplement Unix in Java: what would happen to the paradigm of small utilities that do one job well, that you combine into something greater than the sum of its parts? I think you'll find a lot of short programs are written in C++.

Java wouldn't work very well!

Um, if you reimplemented UNIX in Java you'd probably do a much better job than the UNIX creators were able to do.

In particular, running a program from bash would simply classload it into the existing VM, not invoke a whole separate VM, and then it'd be more or less instant, except you'd have the potential for much more flexible APIs and combinations of tools. Look at PowerShell for an example.

I don't have the technical chops to disagree with you. But rest assured I would not do a better job. Last time I checked java programs do not like operating within the same VM[0]. Last time I looked at it, it was to get a bunch of people running Eclipse remotely from the same JVM instance on a huge box in 2012 or something. It was a no-goer, but some experimental JVM's claimed to support it. [1]

Powershell is a terrible example for the performance point I am trying to make, whatever about its flexibility.

[0] http://www.javalobby.org/java/forums/t72620.html

[0] http://stackoverflow.com/a/13496610

[1]http://www.ibm.com/developerworks/library/j-multitenant-java... (this now looks less experimental but I'm willing to bet >1 instance of eclipse, or bash for that matter would not work very well).

I'm not sure how this works: http://www.excelsiorjet.com/

but it might help to alleviate the problem even though it still has a jvm.

https://en.wikipedia.org/wiki/Java_Classloader

looking at what you mention now, can a program classload itself? seems not: A class with a given name can only be loaded once by a given classloader.

In practice big GUI apps like Eclipse are not intended to share a single VM with lots of other things, let alone multiple instances of itself. If people wanted to write tools that did that (i.e. if it was common) then they could, but it's not enforced. For example even if at the Java level you can separate stuff out, native code to handle the GUI framework might not be expecting it.
I know they weren't written to do so obviously but you can see how it's a related example. You can also understand why if it was the sort of thing that could work it would be worthwhile, what with the amount of RAM each of the Eclipse users had devoted to its (in theory duplicated per user) JVM.

I doubt you would even have to go as far as native extensions for GUI before you start running into problems even though the programs are written in managed code.

Can you better explain how in practice Java programs could share a VM in replacing a typical Unix bash environment/userland?

Would they have to use the special IBM JVM? Would bash have to contain grep as a class? e.g.

machine:~$ grep include Source | grep -v 32 | grep -v 16

Reading about "JAR hell" I really don't think it would work very well.

Interestingly in the IBM link provided earlier they load up substantial non GUI servers such as Tomcat, Jetty and JRuby and achieve a startup time that is twice as fast.

They also have hello world:

Hello World Print "HelloWorld" and then sleep

Multi-tenant JVM: 309

Hand-tuned: 73

Default: 63

Improvement with multitenant: 4.2X to 4.9X

Even with this I think a C++ version would eat it for breakfast. It would be interesting to find out what would happen if a Single JVM were loaded on boot, all programs were loaded into that and compare the JVM based Unix on those terms with e.g. Solaris or something.