I am hoping to get some unbiased information on the relative
performance difference between Java and Objective-C.
More specifically using up to date versions of the Java 6 JRE and
using an up to date GNUStep implementation of Objective-C both running
on Linux.
I can find quite a few articles with people comparing Java vs C++ but
I suppose Objective-C is more niche and tends not to be used in
comparisons.
I know that the opinion still prevails in many circles that Java is
slower and/or significantly slower than code written in C/C++. There
have been articles more recently stating that Java was capable of
outperforming C++ these days.
I am cautious with benchmarks because obviously if someone is trying
to prove a point, that person can be selective about using benchmarks
which support their case.
I know for example that Java has performance limits doing lots of
heavy floating point operations or trigonometry due to not using
native acceleration where it would cause the values to be less
accurate than required by the specifications (Though I believe this
was being addressed).
That used case may only apply to applications that use a lot of
floating point calculations. Many business web based or enterprise
applications may do very little floating point number crunching.
For the sake of context I am in a company that has a system where Java
is used with Servlets to provide a web front end to a system the core
of which is written in Objective-C running on GNUStep.
Considering the dates in some of the Java source I know the system
must have existed at least as long ago as the year 2000.
Back then the versions of Java would have been a lot slower. Java 6
included a big performance increase. It would have made sense back
then to argue that the Objective-C code was going to probably perform
better than Java. Now I don't think the difference would be as big. It
would be within my margin of error that Java may outperform Objective-
C due to compile time optimisation that can be done in Java that
cannot be done in Objective-C that is more geared towards dynamic,
runtime behaviour. In that case I would expect C++ to be faster than
Objective-C generally speaking.
I am hoping to get some feedback from the community to sanitise my
assumptions here.
I don't want to end up looking like an idiot if Objective-C
significantly outperforms Java.
The JNI overhead of having Java talk to Objective-C could cancel out
or more than cancel out any performance gains in Objective-C if the
difference is only slight. This depends also whether the cross
communication comprises of many small JNI calls vs few calls that do a
lot of processing before the call returns.
Any performance information / experience would be helpful.
In theory and from what I know I think it could well be faster. That
is an unbiased view and the unbiased view also hold that it is within
the margin of error for it to be a bit slower too. What I don't have
is any actual performance benchmarks which would give me empirical
evidence for comparison.
I wonder also if it could end up being anecdotal as I really don't
know if the suggestion of porting the Objective-C part of the system
to Java would be dismissed as totally impractical. However it is not a
huge company and the system isn't massive. It is big enough that it
could take significant time but not hopeless.
The other pain with the setup is that the Java code cannot be compiled
on its own. It uses a tool called Jigs to allow Java code to call
Objective-C by generating wrappers to make the objects look like Java
ones. I suppose this might be a GNUStep answer to SWIG with C++.
The compilation uses GNU makefiles because the extra dependency
resolution is being handled by GNU Step extensions to GNU make.
The practicality of this means every new Java file I create is having
to be added to a GNU make file. Each new package requires a GNU make
file in it and the parent package make file has to be updated to add
the new sub directory. This all feels like a bunch of extra tedious
work that I never had to do before when working with Ant. It is an
annoyance but liveable. When illegal argument guys argue the merits of
Ant vs Ivy vs Maven maybe they should spare a thought for the poor guy
using GNU make.
> I don't know if GNUStep preallocates or not. I might have to drudge
> through the documentation and/or user groups to find out.
Carl, I've faced and I often face with this kind of situation (no ObjC,
though). I'm personally sure that in most cases C/C++/ObjC can be replaced
by Java with no performance loss, but when I face with a new customer I'm
pretty cautionary in speaking. The problem is that I know that people not
knowing Java (and VMs in general) are reluctant to believe. The good
approach is a practical one: try to find the time/resources to write a
prototype and measure.
--
Fabrizio Giudici - Java Architect, Project Manager
Tidalwave s.a.s. - "We make Java work. Everywhere."
fabrizio...@tidalwave.it
http://tidalwave.it - http://fabriziogiudici.it
It remains to be seen what the political fallout would be to suggest
replacing the Objective-C code particularly from the Objective-C code
developers. Even if the company accepted moving to pure Java I think
the Objective-C developers are hardly going to thank me for making
their role redundant though I believe they also know Java so I would
hope it would not put their job at risk. At the end of the day I am
talking about 'porting' code and not writing new code from scratch so
I would not think the existing Objective-C work is wasted.
Setting up a new server could be as simple as installing Linux,
installing Java, installing the database and a Servlet container
container then dropping in the War and the system is running.
The existing system requires a bunch of extra work for the benefit of
installing GNU Step and also deploying the Java in such a way that GNU
Step and Java can reference each other.
Performance seems a focus of the technical manager. I have made
changes in the code that were aimed at making the system cleaner and
better architecturally structured but the question I get asked seems
to just be "will this be faster?"
I am approaching the problem on the terms I think my development
manager cares about. If it was a question of clean architecture I
don't know whether GNU Step talking to a Java web layer would have
been chosen. I believe my development manager was involved in the GNU
Step project and so I believed used it because he was a fan of the
technology rather than because it was necessarily a good fit. At least
that is the impression I get. I have not been with the company very
long.
The Java code in the system is probably some of the worsted I have
worked on. Hashtables and Vectors everywhere. Coding to
implementations including all the collections. The concrete
implementations of collections i.e. Vectors and Hashtables are exposed
in the class APIs. The code seems to involve lots of bloated Servlets
frequently with multi page long methods. Many standard Java
contentions can be ignored like using upper case package names not
following JavaBeans style but that is of lesser concern to me than the
coding to implementations and massive complex methods that should have
been broken down into smaller ones.
This system also rolls its own web framework and its own logging
framework.
I would have my work cut out for me just cleaning up the Java. The
Objective-C would be more liveable if the two systems were black boxes
with a well defined boundary interface for communicating back and
fourth but I think the use of wrappers means that Objective-C classes
will just be sprinkled liberally through the Java code.
All the Java code I have seen speaks to me of a lack of thought about
architecture or design patterns / principles. This might be explained
if the top priority is 'performance' or at least perceived
performance.
If you're new, you might be missing some context from previous
projects. If there is a focus on performance, presumably there were
problems regarding performance before. At least, it's an option worth
entertaining and might be more favourable than assuming the manager is
insane.
Are you sure you could not take further steps to automate this build?
For reference, Maven has some support for building non-JVM languages,
and you can call maven from other scripts or scripts from maven. In a
previous job, we had a JNI library wrapping some of ffmpeg's libs,
involving using swig to generate code, and all we had to do that was
out of the ordinary was to start mvn from msys instead of cmd (in
Windows, elsewhere there was no difference at all).
> I believe my development manager was involved in the GNU
> Step project and so I believed used it because he was a fan of the
> technology rather than because it was necessarily a good fit. At least
> that is the impression I get.
Just ask him. It sounds like you're communicating more with us than
with your team. :)
> The Java code in the system is probably some of the worsted I have
> worked on. Hashtables and Vectors everywhere.
That probably indicates its age or when the coders last deliberately
learned anything, rather than quality directly.
> Coding to implementations including all the collections.
That isn't a big problem and can be refactored out fairly automatically.
I'd suggest code reviews for most of your remaining points.
> This system also rolls its own web framework and its own logging
> framework.
Choose a logging framework, rename your logging framework's methods to
match that, then delete the jar and go through fixing the imports. :)
> I would have my work cut out for me just cleaning up the Java. The
> Objective-C would be more liveable if the two systems were black boxes
> with a well defined boundary interface for communicating back and
> fourth but I think the use of wrappers means that Objective-C classes
> will just be sprinkled liberally through the Java code.
This is probably your bigger problem. I'd be looking to create
islands of pure Java and islands of pure Objective-C, and to stretch
an analogy, form continents of each connected by satellite link.
> All the Java code I have seen speaks to me of a lack of thought about
> architecture or design patterns / principles.
So introduce them as you see fit but measure the performance so that
you are armed for when you are questioned.
--
You received this message because you are subscribed to the Google Groups "The Java Posse" group.
To post to this group, send email to java...@googlegroups.com.
To unsubscribe from this group, send email to javaposse+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.
But in the average, Java is faster simply because 90% of the responsibility for memory management is on the shoulders of the runtime; so a mediocre programmer (or just a good programmer who has too much stuff to do to waste time in optimization) will easily write a program that has good memory management performance. This is harder in the case of C/C++, where, for memory-intensive systems, you can easily beat Java's performance but you need either a quite good programmer, or lots of time to burn in optimization - preferably both.
--
You received this message because you are subscribed to the Google Groups "The Java Posse" group.
To view this discussion on the web visit https://groups.google.com/d/msg/javaposse/-/5XaYGBOmjx4J.
That said, object allocation in generational space based heaps has proven to be a huge performance win. You talk about cheap allocation. The reason we have cheap allocation is that generational spaces makes fast-path allocations possible. And for the same reasons, generational spaces makes reclamation almost free. In the spirit of "there is no free lunch", the cost of generational spaces comes when you need to move things from one memory pool to another. But again, this cost is generally smallish in most systems because most data is discarded after a few machine cycles.
You know, I was in an interview with a company that was proto=typing in C++ because they believed in some of the arguments put forth here.and I think that demegrating Java developers is just down right wrong. I used to work in Smalltalk, C, C++ and various forms of assembler when needed. I spent today looking
at some C++ code that I need to port to OSX so that I might get a better view of chip level counters. I wasn't the only Java developer looking at this stuff. Why are all these C++ guys working with Java? It's because I want to solve interesting problems and while mucking about with pointers is a nice recreational programming sport for some, it's no longer interesting.for me. The C++ bigotry that existed in the company that interviewed me also brought that company down. Their clever C++ guys could have easily as been working in Java and they might have made it to market before their funding ran out. (I declined the offer).You're statement that one can easily beat a Java programmer isn't so true in a general sense. The JVM can optimize to instruction sets that are specific to single rev's of a specific chip. GCC isn't going to do that for you unless you build a different binary for every different version of every single chip out there. It's impractical and so one builds to the common instruction set leaving some nice performance optimizations on o the table. NUMA is one example where your application doesn't need to be recompiled to take advantage of different chip architectures. Some of the optimizations provided my the JVM produce non-obvious native code that I doubt that even the best optimizing C++ compilers could provide. Try looking at the assembler dumped from a fast debug version of the JVM and ask the question, could I have hand rolled that? Ok, in some cases the answer will be yes but there will be just as many where the answer was no.Regards,Kirk
A+
Osvaldo
On Thursday, December 1, 2011 7:36:04 AM UTC-5, KWright wrote:
Sure you can. The so-called "placement new"[1] allows you exact control over where you stick your objects.There are also various implementations available, such as pool[2], from the Boost libraries
There's a limit to how far you can take this though. C++ still forces you to make a lot of it far more explicit, so there's a cognitive overhead to how far you can take it in an ever-growing system.
It also makes for some real fun and games when debugging & profiling
[1] http://stackoverflow.com/questions/222557/cs-placement-new
On 1 December 2011 11:04, Ricky Clarkson <ricky...@gmail.com> wrote:
I imagine that implementations of malloc/free exist or could be written that preallocate. Thus this advantage can be achieved in C.
From: Kevin Wright <kev.l...@gmail.com>Sender: jav...@googlegroups.com
Date: Thu, 1 Dec 2011 11:46:34 +0000
To: <jav...@googlegroups.com>ReplyTo: jav...@googlegroups.com