News for hackers. Stuff that matters.
Re:A performance comparison between Java and C on the Nexus 5 by jeswin on Monday April 14, 2014 @10:13AM (#7586242)
I've been an Android user since my first smartphone. I've heard several times iPhone users complain that Android equivalents of their iOS apps felt sluggish; though they couldn't pinpoint it exactly. If these numbers are true, it might well be true. Objective-C might not suffer from such a significant slowdown.

I think it is one of the things Apple gets right; they know what matters. As an outsider to the iOS/Mac ecosystem I've often felt that Apple makes trade-offs in productivity to achieve a better experience for the end user. While these tests aren't indicative of typical app performance (most apps aren't doing math in a loop), an order of magnitude performance difference is enough to show up on many apps.

I wonder if Google made a mistake by not choosing native code for Android apps. We have heard forever about Java (and other run-times) getting close to C in performance, but outside of specific test cases native code still runs circles around everything else out there.

Re:A performance comparison between Java and C on the Nexus 5 by lhl on Monday April 14, 2014 @10:31AM (#7586353)
While I'm sure Dalvik contributes, Android has had many more serious issues in terms of user responsiveness.

* Android devices have very laggy touch responsiveness in general, while this is something Apple has spent considerable effort optimizing [1]

* Only in recent revisions (Project Butter [2]) has Android made significant improvements to its general UI lag/smoothness issues. At various times, Google employees have gone into extensive descriptions of why the UI is so janky [3][4]

* Many of the default Android elements were for quite a long time, very unoptimized - this included calls w/ lots of overdraw, or lack of node recycling for lists. This forced app developers to take on the bulk of performance optimization. You can take a guess how often that is done well. [5]

Over time, Android the OS, SDK/API, tools have all improved but I believe your second paragraph gets it right. At the end of the day, people at Apple cared a lot about getting the first versions of iOS to feel great. No one at Google cared enough about about it. Even today, when you compare the iPhone to the latest Nexus devices, there's lots of hardware integration issues that will probably never get fixed (outside of community patches).

[1] http://venturebeat.com/2013/09/19/apples-iphone-5-touchscree...

[2] http://www.androidpolice.com/2012/07/12/getting-to-know-andr...

[3] https://plus.google.com/105051985738280261832/posts/2FXDCz8x...

[4] http://lazytechguys.com/news/google-dev-explains-why-android...

[5] http://www.curious-creature.org/2012/12/01/android-performan...

Re:A performance comparison between Java and C on the Nexus 5 by kllrnohj on Monday April 14, 2014 @02:14PM (#7587816)
[1] The Android code for that test is messed up, and suffers from a race condition and isn't tied to vsync like a normal Android app is. There's a pull request on their github page to fix it, but they haven't accepted it. Regardless, this is a hardware thing not a software one. Apple uses very, very good touch screens. The Nexus 5 also has a really good touch screen, with total touch-to-display latency in the 60ms range.

[4] is total horseshit. He doesn't know squat about any of the platforms. iOS devs also called him out for getting just about everything wrong about how iOS works.

[5] is something iOS devs totally also have to do as well. That is so not an Android-specific thing.

Re:A performance comparison between Java and C on the Nexus 5 by asveikau on Monday April 14, 2014 @11:18AM (#7586630)
> [4] http://lazytechguys.com/news/google-dev-explains-why-android...

Man that was a weird read. Guy spends a few months interning and all of a sudden talks about his profound connection to the campus, the fundamental flaws in the product architecture, but watch out! He may be biased since he will be interning on a competing product the next summer!

Regardless of the facts of the matter this seems like a very non-authoritative source.

Re:A performance comparison between Java and C on the Nexus 5 by magicalist on Monday April 14, 2014 @01:20PM (#7587480)
It's like no one actually reads Dianne Hackborn's post (#3 above), which was in direct response to that guy's musings going viral when he had no idea what he was talking about.

edit: oops, that was the post that sparked the original specious musings. I meant this followup one: https://plus.google.com/105051985738280261832/posts/XAZ4CeVP...

Re:A performance comparison between Java and C on the Nexus 5 by asveikau on Monday April 14, 2014 @01:28PM (#7587538)
What drew me to #4 was the baiting headline (Google dev explains...)
Re:A performance comparison between Java and C on the Nexus 5 by simmons on Monday April 14, 2014 @11:18AM (#7586628)
From my experience with working on Android internals, I also get the impression there is a ridiculous amount of IPC happening during normal operation, much of which involves Dalvik components (such as the activity manager) as intermediaries. I've sometimes wondered if this could contribute to a noticeable performance degradation.

Quantifying this IPC might make an interesting experiment and blog post...

Re:A performance comparison between Java and C on the Nexus 5 by hackcasual on Monday April 14, 2014 @11:50AM (#7586869)
The IPC implementation is Binder, and I believe the overhead, even in the G1 days was microseconds.
Re:A performance comparison between Java and C on the Nexus 5 by simmons on Monday April 14, 2014 @12:48PM (#7587245)
Binder itself is very fast. I'm mostly thinking about the overhead of higher-level constructs build on top of binder (broadcast intents, etc.) that are handled in Dalvik code and that can become numerous as various apps make connections to various other apps.
Re:A performance comparison between Java and C on the Nexus 5 by mdwrigh2 on Tuesday April 15, 2014 @02:03AM (#7590502)
> lack of node recycling for lists

Adapter#getView[1] has been around since API 1, which is used in ListView (as well GridView, etc.) to recycle view nodes.

[1]: http://developer.android.com/reference/android/widget/Adapte..., android.view.View, android.view.ViewGroup)

Re:A performance comparison between Java and C on the Nexus 5 by thrownaway2424 on Tuesday April 15, 2014 @12:39AM (#7590330)
Interesting post. I would throw in a social angle. Android will suffer from UI lag until it's scrapped and rewritten, because its early development was heavily influenced by Romain Guy, a developer who was a huge proponent of Swing and who actually thought that JavaFX was a good idea. This is a person who has basically never seen a responsive UI and cannot understand what makes Android "laggy" at a deep level. Some of your other links show that Android is pretty long on people who will write long defensive blog posts, short on people who can make efficient, responsive graphics stacks.

Social problem, basically.

Re:A performance comparison between Java and C on the Nexus 5 by agumonkey on Tuesday April 15, 2014 @08:58AM (#7591530)
Even post 4.1 isn't smooth enough for you ? Project butter was a great leap forward to me, and it seems romain guy was involved in it

https://www.google.com/search?q=romain+guy+project+butter

Re:A performance comparison between Java and C on the Nexus 5 by zht on Monday April 14, 2014 @04:27PM (#7588668)
[4] was a post written by a QA intern on a different team. His post was thoroughly debunked by Dianne. I know the guy in person and he is a general loud mouth who never hesitates to spew nonsense about topics that he knows nothing about.
Re:A performance comparison between Java and C on the Nexus 5 by chrisdevereux on Monday April 14, 2014 @11:18AM (#7586627)
> If these numbers are true, it might well be true. Objective-C might not suffer from such a significant slowdown.

Kinda. I imagine that if these benchmarks were run on idiomatic Objective-C, they'd be an order of magnitude slower than Java. All method calls are un-inlineable and often require a hash table lookup to resolve.

However, the nice thing about Objective-C is that it's ridiculously easy to write performance-critical stuff in C or C++, then expose it with a nice OO interface. Which means that you (or, more likely, the people who wrote the library you're using) are more likely to bother. That and the lack of GC making latency easier to reason about.

So while it is probably easier to write performant UIs in Objective-C than Java, it isn't because of the reasons mentioned here.

Re:A performance comparison between Java and C on the Nexus 5 by gmac on Monday April 14, 2014 @11:26AM (#7586682)
Yes — in fact, it's arguably more natural in most cases to write your performance-critical stuff (e.g. math in loops) in plain C. There's rarely any reason to start boxing values up in NSNumbers and then unboxing them again.

In addition, Apple's Accelerate framework makes it easy and natural to take advantage of SIMD for further speedups — you can get powerful vector operations with single function calls. This seems to have no Android equivalent.

Re:A performance comparison between Java and C on the Nexus 5 by pjmlp on Monday April 14, 2014 @01:05PM (#7587374)
> This seems to have no Android equivalent.

Renderscript?

Re:A performance comparison between Java and C on the Nexus 5 by gmac on Monday April 14, 2014 @01:22PM (#7587492)
Thanks — previous Googling hadn't turned this up for some reason.
Re:A performance comparison between Java and C on the Nexus 5 by Someone on Monday April 14, 2014 @02:02PM (#7587752)
"If these benchmarks were run on idiomatic Objective-C"

    s/idiomatic/pure/
I haven't programmed it much, but to me, idiomatic objective-C is when you use it as a sort-of scripting layer on top of your C code. No sane programmer would write ten layers of Objective-C message passing code; two or three is fine, on the bottom of your call stack (and hence, rarely executed)
Re:A performance comparison between Java and C on the Nexus 5 by mikeash on Monday April 14, 2014 @09:45PM (#7589883)
Objective-C message sends always require a hash table lookup to resolve. That is the fast path. (Edit: almost always. I forgot about the vtable path for a few selectors. It doesn't affect most code and I don't think it's even used outside of x86-64, but it is a non-hash-table path.)

However, implying that "require a hash table lookup" is slow isn't really right. The message send implementation is extremely optimized and takes about a dozen CPU cycles to execute last I measured. To put that in perspective, that means that an Objective-C message send on the fast path (which happens 99.99% of the time, the slow path basically just happens once per message/class combo) costs about as much as two C function calls, or one and a half C++ virtual function calls.

Message send overhead in a typical Objective-C app is small. 10% would be high, for really message-heavy code, and 5% is more typical. Most Objective-C code is not messaging so it's still fast.

Take these benchmarks as an example. To write them in "idiomatic Objective-C" you'd change almost nothing. You'd either get rid of the few C++-isms (templates for min/max functions, parameters passed by reference, no big deal) or compile the file as Objective-C++. You'd never write code like this using Objective-C objects. In addition to be slower, it would be harder to write, harder to read, and much larger.

Re:A performance comparison between Java and C on the Nexus 5 by chrisdevereux on Tuesday April 15, 2014 @08:37AM (#7591440)
You're right... I sort of contradicted myself there by calling an implementation using Objective-C objects 'idiomatic', since nobody in their right mind would implement that example using NSArrays and boxed values.

My point was really that Objective-C isn't always faster than the equivalent Java (a function call, hash lookup and jump is fast in most contexts, but it's still infinitely slower than nothing, which is the overhead of a JIT-inlined method call), but that being a superset of either C or C++ means that it can be faster when it needs to be. Which is ultimately what matters.

Re:A performance comparison between Java and C on the Nexus 5 by mikeash on Tuesday April 15, 2014 @10:33AM (#7592008)
Yep, you can definitely construct Objective-C code that would be way, way, way slower than equivalent Java code. A trivial example would be something like for(int i = 0; i < 1000000000; i++) [obj self];. I imagine any decent Java JIT will be able to detect that this loop does nothing and eliminate it entirely.

However, my point is that not only can you write faster Objective-C code, but that most normal Objective-C code will be faster, because most normal Objective-C code isn't that message heavy. So it's not just that it can be faster, but that it usually will be. Typically. Depending on what you're doing.

Re:A performance comparison between Java and C on the Nexus 5 by kllrnohj on Monday April 14, 2014 @02:16PM (#7587833)
> I wonder if Google made a mistake by not choosing native code for Android apps.

Seeing as Android runs on a lot more than just ARMv7, no, they didn't appear to make a mistake here at all.

Apple can tell developers to compile their app twice for ARMv7 w/ NEON & ARMv8-A64, but is Google going to go tell everyone to compile for ARMv6 (Android devices running this are still shipping), ARMv7 w/o NEON, ARMv7 w/ NEON, ARMv8 (not here yet on Android, but obviously coming), MIPS, X86, etc...?

> We have heard forever about Java (and other run-times) getting close to C in performance, but outside of specific test cases native code still runs circles around everything else out there.

The vast majority of the Java code in an Android app isn't performance-critical either. The code that actually renders an app is all in native anyway. The code to handle touch events and such isn't, but the difference between .1ms and .2ms isn't going to break the 16ms bank either.

Re:A performance comparison between Java and C on the Nexus 5 by fleitz on Monday April 14, 2014 @02:28PM (#7587899)
They don't 'tell' you, you press Command-B and it happens.

When there are new architectures, you get a warning in XCode and press "Upgrade Project".

Right now my 'default' build is for armv7, armv7s, armv8, x86, x86_64. This setup required no effort on my part. I just created a new project.

Re:A performance comparison between Java and C on the Nexus 5 by Tmmrn on Tuesday April 15, 2014 @03:35AM (#7590752)
> ARMv7 w/o NEON

Several of Google's own google apps depend on native libraries. Try to install google apps for android 4.2+ on a device without neon like tegra2 and see how many of them actually work and how many crash with SIGILL.

Re:A performance comparison between Java and C on the Nexus 5 by Ologn on Monday April 14, 2014 @01:53PM (#7587691)
> I wonder if Google made a mistake by not choosing native code for Android apps. We have heard forever about Java (and other run-times) getting close to C in performance, but outside of specific test cases native code still runs circles around everything else out there.

You can use native code for Android apps. I do. In the NDK samples there is an app called NativeActivity which is 100% C/C++. You compile an APK without writing any Java/Dalvik code.

From my anecdotal knowledge, most of the popular Android games are written mostly in C++, using the OpenGL ES library, and have a common code base with their iOS counterparts. Maybe they are all native code, maybe they use some Java and JNI stuff, but they are mostly C++. So Android is native on the game side, where it is needed.

A deep look at how all native code runs will show some non-native system code run when it launches, but that becomes pedantry if performance and not purity is the focus.

Android is cleft in two - applications are mostly Java/Dalvik with maybe some JNI access to C/C++ libraries, games from all my discussions with Android game developers are usually mostly the same C++ code and OpenGL ES they are using on iOS.

One example I know a little about is Jigzo. It is an open source game which is C++ and uses OpenGL and SDL libraries. The original developer ported it to iOS. I ported it to Android. Same basic code base, with a few tweaks for each OS. I changed the name from Jigzo to Jigsaw Puzzles on Play though.

Re:A performance comparison between Java and C on the Nexus 5 by mdwrigh2 on Tuesday April 15, 2014 @02:36AM (#7590596)
The NDK is great for games, but is really not meant for other types of applications. It lacks a ton of mechanisms to interact with other pieces of the platform.
Re:A performance comparison between Java and C on the Nexus 5 by pjmlp on Tuesday April 15, 2014 @04:10AM (#7590839)
I also do use NDK for my hobby graphics programming, but outside games it is pretty much handicapped and very few people like to write JNI code everywhere. Not to mention the performance issues due to marshaling.

At least now the NDK has some sample source code for JNI helper classes to ease the pain.

Qt is the only sane approach for doing full Android applications in C++, but then one is writing multiplatform code anyway.

Re:A performance comparison between Java and C on the Nexus 5 by smrtinsert on Monday April 14, 2014 @11:11AM (#7586571)
First, the word iphone isn't even mentioned in the article, but its funny how quickly HN drops into an iphone vs. android

Second, the author points out NDK over Java as a solution which is already leveraged by some popular apis transparently from java, such as libgdx.

Finally, the ui is responsive enough. My biggest annoyance whenever I have to help my in laws or my parents with their iphones and there is no back button - I don't notice any significant difference between their iphones and my Galaxy S3, and I'm sure Samsungs phones have only gotten better.

Re:A performance comparison between Java and C on the Nexus 5 by jaegerpicker on Monday April 14, 2014 @12:37PM (#7587156)
>>Finally, the ui is responsive enough.

I have to strongly disagree here. I'm a mobile dev, I work on Android and iOS. My main phone is an iPhone 5s, recently I tried switching OS just so that I would be more comfortable with the different OS's day to day idioms. I couldn't stand Android, it was sooo laggy feeling compared to a iPhone or even a windows 8 phone. Both Apple and Microsoft have large leads in user experience and speed. Don't get me wrong Android is certainly better than either in it's own way but performance and responsiveness are not it's strong suite. 3 apps that the difference was obvious to me are: Google Maps (the ios version feels way smoother), Evernote, and the facebook app. Also see the yahoo weather app the difference was incredible. Phones I used in testing: HTC One, Samsung S4, Nokia Lumia 1520, and iPhone 5S

Granted all of this was based upon personal experience and isn't a scientific study but to me the difference was absolutely clear. Perhaps if I had only used an Android device I wouldn't have noticed the difference as much but having been a long term iOS user I could not stand it.

Re:A performance comparison between Java and C on the Nexus 5 by rprospero on Monday April 14, 2014 @03:21PM (#7588203)
> Granted all of this was based upon personal experience and isn't a scientific study but to me the difference was absolutely clear.

Thanks for including that line, because my personal experience is the exact opposite. I have a four year old android phone and I dread any time I need to use my wife's one year old ipod. I find the lag on the ipod slow to the point of almost being unusable. Every time I use it, there's at least one point where I'll put down the iPod to go do something else while I wait for it to catch up with me.

It's amazing how much personal experiences can differ.

Edit: updated possibly relevant details

Re:A performance comparison between Java and C on the Nexus 5 by TylerE on Monday April 14, 2014 @10:44PM (#7590054)
Worth pointing out that there is a pretty big drop in spec from an iPhone 5 to an iPod 5, the SoC is two full generations behind.
Re:A performance comparison between Java and C on the Nexus 5 by abjuk on Wednesday April 16, 2014 @11:41AM (#7598444)
This. Also, a year ago Apple was still selling some models of the 4th gen iPod Touches, which are the equivalent of a three year old iPhone 4 but with half the ram.
Re:A performance comparison between Java and C on the Nexus 5 by mdwrigh2 on Tuesday April 15, 2014 @02:32AM (#7590585)
> Phones I used in testing: HTC One, Samsung S4, Nokia Lumia 1520, and iPhone 5S

Honestly, try a Nexus 5 if you get the chance. The hardware in the phone makes a huge difference (and it's often in places that aren't benchmarked, like the touch controller).

Re:A performance comparison between Java and C on the Nexus 5 by pjmlp on Tuesday April 15, 2014 @03:54AM (#7590802)
Both iOS and Windows 8 have native compilation only as delivery model and most likely the reason driving ART's design as Dalvik replacement.
Re:A performance comparison between Java and C on the Nexus 5 by matwood on Monday April 14, 2014 @03:32PM (#7588276)
I have found Android nice to use only on Nexus devices. For whatever reason the other devices always feel slow and have random issues.
Re:A performance comparison between Java and C on the Nexus 5 by stusmall on Monday April 14, 2014 @04:06PM (#7588515)
I don't know what other devices you've used but Samsung uses its own keyboard on some (maybe all? I've only used a few) of their phones. Its not the fastest thing out there. Switching that out with the Google one can make a huge difference in perception of the phone's performance.
Re:A performance comparison between Java and C on the Nexus 5 by matwood on Monday April 14, 2014 @05:17PM (#7589022)
I've used HTC, Samsung, and currently use a Nexus5 full time. Whenever I have to use friends iPhones now they feel really dated compared to the Nexus 5. Android really turned a corner not long ago with 4.x and devices like the Nexus 5.
Re:A performance comparison between Java and C on the Nexus 5 by gmac on Monday April 14, 2014 @11:29AM (#7586706)
(Equally, my biggest annoyance on Android is often the lack of an on-screen back button, and the small but annoying proportion of times when the hardware back button takes me somewhere other than I expected.)
Re:A performance comparison between Java and C on the Nexus 5 by sizzle on Monday April 14, 2014 @11:47AM (#7586850)
You can get around the back button part by rooting and allowing double tap of back arrow to jump between last open application. This solved that pain point for me
Re:A performance comparison between Java and C on the Nexus 5 by coin on Monday April 14, 2014 @07:26PM (#7589497)
People don't want to have to root a device to work around usability issues. That's why iOS devices are so popular, out of the box they just work (for the most part).
Re:A performance comparison between Java and C on the Nexus 5 by sizzle on Tuesday April 15, 2014 @08:34PM (#7595239)
I was just suggesting this workaround personally after having been frustrated by the back button myself
Re:A performance comparison between Java and C on the Nexus 5 by mikeash on Monday April 14, 2014 @09:46PM (#7589889)
On the other hand, when you do bump into a problem, you generally can root Android devices, while iOS is getting to be pretty rough there.
Re:A performance comparison between Java and C on the Nexus 5 by bananas on Tuesday April 15, 2014 @04:00AM (#7590811)
I've used both extensively. When iOS screws up, which at least it does in my house regularly[1], you're SOL. We're moving to Android devices slowly (up two Moto Gs at the moment).

[1] we have three iOS devices and I'm the loveless tech support for them.

Re:A performance comparison between Java and C on the Nexus 5 by StavrosK on Tuesday April 15, 2014 @05:37AM (#7591026)
Which app does that?
Re:A performance comparison between Java and C on the Nexus 5 by sizzle on Tuesday April 15, 2014 @08:36PM (#7595250)
after you root, install Xposed framework and you can get the GravityBox module which will enable a ton of customization. Read the tutorials on XDA forums if you need help, enjoy!
Re:A performance comparison between Java and C on the Nexus 5 by double051 on Monday April 14, 2014 @03:23PM (#7588219)
The NDK is a total 'bolt-on' solution to the problem, and support within the Android dev tools is basically non-existent.

The biggest tragedy is that Google had a chance to make a better NDK experience with Android Studio, but instead they chose to ignore it completely. With Eclipse you at least had an official add-on for NDK support, but now you're expected to manage it with your Gradle files by hand. Now, even more than before, you're at the whim of solutions on Stack Overflow.

Re:A performance comparison between Java and C on the Nexus 5 by mdwrigh2 on Tuesday April 15, 2014 @02:11AM (#7590527)
NDK support is being worked on. There are samples[1] of the API, but it's largely undocumented and still a work in progress.

There's a reason AS hasn't hit 1.0 yet: it isn't ready.

[1]: http://docs.google.com/viewer?a=v&pid=sites&srcid=YW5kcm9pZC...

Re:A performance comparison between Java and C on the Nexus 5 by pjmlp on Tuesday April 15, 2014 @04:01AM (#7590819)
I think having a few ex-Sun Java guys might have influenced that decision. Since all other mobile platforms offer better native support.

This is just my personal opinion.

Re:A performance comparison between Java and C on the Nexus 5 by hcho on Monday April 14, 2014 @10:22AM (#7586296)
The perceived sluggishness of Android was down to how the system was architected, especially around the way the UI thread was prioritised. I say was, because Google threw a lot of hardware and money to workarounds for that problem. It is less noticeable these days. They won't be able to fix it completely without a ground up redesign though.
Re:A performance comparison between Java and C on the Nexus 5 by officialjunk on Monday April 14, 2014 @10:29AM (#7586335)
I also read a breakdown of the touch screen scan rate (the refresh rate at which touch gestures are captured), which was significantly faster for ios devices. That also contributed to the difference in feel. Do you know if android devices have "caught up?"
Re:A performance comparison between Java and C on the Nexus 5 by gareim on Monday April 14, 2014 @10:32AM (#7586360)
I think you might be interested in this:

http://forum.xda-developers.com/showthread.php?t=2706200

I have had an S3, iPhone 5, and HTC One (M7) and the iPhone 5 definitely felt the smoothest, but now I'm interested in seeing if the M8 really has leveled the playing field.

Re:A performance comparison between Java and C on the Nexus 5 by mdwrigh2 on Tuesday April 15, 2014 @02:40AM (#7590612)
The scan rate isn't typically the worst factor, which is usually between 120-300hz (meaning a max additional latency of 3 - 30ms), but rather deriving meaning from that data is. Filtering in a noise-free environment typically adds a few scan frames of latency, which is what puts devices in the 60-120ms of latency, and a noisy environment (i.e. plugged in to a cheap charger) can easily up that to a few hundred ms of latency.
Re:A performance comparison between Java and C on the Nexus 5 by mdwrigh2 on Tuesday April 15, 2014 @02:16AM (#7590543)
> The perceived sluggishness of Android was down to how the system was architected, especially around the way the UI thread was prioritised

UI thread priority has been debunked time and time again: https://plus.google.com/105051985738280261832/posts/XAZ4CeVP...

Even if it hadn't been, what evidence is there that it would require a ground up redesign?

Re:A performance comparison between Java and C on the Nexus 5 by mikeash on Monday April 14, 2014 @09:47PM (#7589895)
The UI thread doesn't get any special treatment on iOS, so unless Android is deprioritizing its UI thread, it doesn't seem likely that this would be a problem.
Re:A performance comparison between Java and C on the Nexus 5 by mdwrigh2 on Tuesday April 15, 2014 @02:19AM (#7590551)
Doesn't get any special treatment by Android either. All other threads get set to background priority (well, most, but all that we care about), which by default can only consume 10% of CPU resources.
Re:A performance comparison between Java and C on the Nexus 5 by bluerobotcat on Monday April 14, 2014 @10:26AM (#7586316)
In the long run, having a more modern language should benefit Android because it means the barrier of entry is lower for programmers.

In the meantime it does seem likely that Java has a non-negligible performance cost. My personal worry is that fast Garbage Collectors usually assume that twice the memory is available than is used. That might put the fact that Android phones typically have more memory than Apple devices in an interesting light.

Re:A performance comparison between Java and C on the Nexus 5 by pkolaczk on Monday April 14, 2014 @12:09PM (#7586994)
I found two problems with your reasoning:

First, the overhead of GC depends not only on the heap size, but also on the allocation rate and allocation profile. For reasonable allocation rates found in typical GUI apps, most Java GCs do extremely well having very little additional memory, like only 20% more than the live set size. There is no "twice as much" assumption anywhere in their design.

Second, manual memory managers do have their own overhead too, in form of bookkeeping (e.g. free lists) and internal fragmentation. Fragmentation can be sometimes much worse than GC memory overhead for long running applications, because GC memory overhead is typically bounded, while fragmentation is either unbounded or has extremely high upper bounds (like 10x in "fast" allocators).

Re:A performance comparison between Java and C on the Nexus 5 by munificent on Monday April 14, 2014 @01:20PM (#7587483)
> There is no "twice as much" assumption anywhere in their design.

There is in that the nursery collector is often a simple Cheney-style copying collector that wants two semispaces. But that's only one of the generations. There's definitely no requirement that total GC memory is double the used space.

Re:A performance comparison between Java and C on the Nexus 5 by rsynnott on Monday April 14, 2014 @11:38AM (#7586770)
_Is_ Java significantly more 'modern', than Objective C, though? How? It's not like it's much newer; development started in 1991, vs early 80s for ObjC.
Re:A performance comparison between Java and C on the Nexus 5 by pjmlp on Monday April 14, 2014 @01:17PM (#7587462)
- GC

- namespaces

- memory safe

- you don't have to type @ and [] everywhere to switch between dynamic and static worlds

As for the vm thing, there are also commercial native compilers, even though the general HNer tend not to be aware of them.

Re:A performance comparison between Java and C on the Nexus 5 by rsynnott on Monday April 14, 2014 @05:02PM (#7588920)
> GC

Thus giving Android developers all the fun of dealing with GC pauses. There's a lot to be said for ARC, really; I'm quit glad Apple ditched their brief experiment with ObjC GC.

> namespaces

I'll give you that one; lack of namespaces it the worst thing about ObjC.

> ... Dynamic and static worlds...

I'm not sure what you mean here; Java is a statically typed language, and does not have a 'dynamic world'. ObjC has a fo of optional dynamic typing, which is arguably modern, though also only arguably a good thing.

Re:A performance comparison between Java and C on the Nexus 5 by pjmlp on Monday April 14, 2014 @05:25PM (#7589059)
> I'm quit glad Apple ditched their brief experiment with ObjC GC.

Because they failed to implement a GC that didn't crash all the time, as the Apple forums used to testify before ARC was touted as the best thing since sliced bread.

The wonders of mixing Objective-C libraries compiled in mixed mode.

> I'm not sure what you mean here;

The mixed nature of Objective-C.

With @ and [] one is in Smalltalk land. Without them, one is in C world.

> Java is a statically typed language, and does not have a 'dynamic world'.

Yes it has, via reflection, annotations and dynamic bytecode generation.

Re:A performance comparison between Java and C on the Nexus 5 by msbarnett on Monday April 14, 2014 @05:38PM (#7589120)
> With @ and [] one is in Smalltalk land. Without them, one is in C world.

This is an odd and not particularly true way of looking at things. [] (for message sending), is merely some syntactic sugar for the objc_msgsnd function call.

Re:A performance comparison between Java and C on the Nexus 5 by pjmlp on Tuesday April 15, 2014 @01:51AM (#7590473)
Which could have been implemented in a better way, e.g. Dylan does dynamic dispatch with multi-methods without requiring me to type [] everywhere. A real pain in non US keyboards.
Re:A performance comparison between Java and C on the Nexus 5 by rat87 on Tuesday April 15, 2014 @04:56AM (#7590939)
Also Dynamic casts(w/exceptions) and virtual methods/Dynamic dispatch which do provide some dynamicity not easy/natural in c.
Re:A performance comparison between Java and C on the Nexus 5 by mikeash on Monday April 14, 2014 @09:49PM (#7589900)
Your first three points are good, but are you seriously suggesting that Java is "more modern" because its method call syntax uses a dot instead of brackets?
Re:A performance comparison between Java and C on the Nexus 5 by pjmlp on Tuesday April 15, 2014 @01:54AM (#7590480)
Yes, because [] was a pre-processor hack back when Objective-C was invented and the compiler was actually a translator to C.

A means of gathering the code, dump it into a series of objc_msgsnd, without doing much of real compiler work.

There are languages with Smalltalk semantics without forcing me to type @ and [] multiple times per line, a pain in non US keyboards.

Re:A performance comparison between Java and C on the Nexus 5 by antimagic on Tuesday April 15, 2014 @06:50AM (#7591166)
Seriously? And all of those {} that you type in Java-land, they're magically easy to type? Which is of course a red-herring, because neither is enough of a drama to be taken seriously. You deal with it for a day or two and then forget about it.
Re:A performance comparison between Java and C on the Nexus 5 by mikeash on Tuesday April 15, 2014 @10:30AM (#7591995)
What kind of code are you writing where you have to type @ multiple times per line?
Re:A performance comparison between Java and C on the Nexus 5 by pjmlp on Tuesday April 15, 2014 @11:56AM (#7592501)

    id map = @{ @"my key": @123};
Re:A performance comparison between Java and C on the Nexus 5 by rsynnott on Thursday April 17, 2014 @11:38AM (#7604252)
Of course, in Java, this would look like (at best, using a third party thing):

ImmutableMap.builder().put("my key", 123).build();

Which hardly seems neater (especially in a more realistic case where you have more than one entry).

Re:A performance comparison between Java and C on the Nexus 5 by pjmlp on Thursday April 17, 2014 @01:44PM (#7605064)
The point was the pain to type @ in keyboards other than US.
Re:A performance comparison between Java and C on the Nexus 5 by mikeash on Tuesday April 15, 2014 @12:48PM (#7592866)
Surely you're not doing that anywhere close to every line.
Re:A performance comparison between Java and C on the Nexus 5 by pjmlp on Monday April 14, 2014 @01:08PM (#7587396)
The main issue is the quality of Google's implementation, don't generalize the language vs implementation.

Apparently they haven't done any changes since JIT was introduced in 2.3 version. Additionally we have ART without any information whatsoever about future plans.

Re:A performance comparison between Java and C on the Nexus 5 by pjmlp on Monday April 14, 2014 @11:11AM (#7586569)
> I wonder if Google made a mistake by not choosing native code for Android apps.

I would say yes.

> We have heard forever about Java (and other run-times) getting close to C in performance, but outside of specific test cases native code still runs circles around everything else out there.

Please don't mix language vs implementation.

Re:A performance comparison between Java and C on the Nexus 5 by ibrahima on Monday April 14, 2014 @02:10PM (#7587798)
Eh, most apps are not doing computations like this in their main thread. Android does have some touch responsiveness issues, but this article has nothing to do with that.
Re:A performance comparison between Java and C on the Nexus 5 by personZ on Monday April 14, 2014 @10:59AM (#7586512)
This benchmark is a bit artificial (though still interesting and illuminating), given that much of what we do on our smartphone is not so computationally intensive in our own code, but instead most apps are a relatively thin layer of glue and duct tape that coordinates and orchestrates the underlying native platform code.

The choice of Java/Dalvik does seem like a mistake, and was a carry-over of Android coming from classic J2ME roots, which worked well with Google's love of all things Java.

Re:A performance comparison between Java and C on the Nexus 5 by mdwrigh2 on Tuesday April 15, 2014 @02:31AM (#7590580)
>The choice of Java/Dalvik does seem like a mistake, and was a carry-over of Android coming from classic J2ME roots, which worked well with Google's love of all things Java.

Where did you get the idea that Android had J2ME roots? It definitely did not.

Re:A performance comparison between Java and C on the Nexus 5 by pjmlp on Tuesday April 15, 2014 @04:06AM (#7590827)
At least they had planned J2ME support as well.

http://www.theverge.com/2012/4/25/2974676/this-was-the-origi...

Re:A performance comparison between Java and C on the Nexus 5 by mdwrigh2 on Tuesday April 15, 2014 @11:33AM (#7592339)
Through a compatibility mode. The platform itself was specifically not J2ME.
Re:A performance comparison between Java and C on the Nexus 5 by personZ on Tuesday April 15, 2014 @09:38AM (#7591699)
Rubin came from Danger, which was a J2ME company. They started Android (pre-Google) as yet another J2ME company. When they were eventually acquired by Google, Google didn't want to play ball with Sun, so they went with a clean-room simile, but, to consult actual Google documentation (three years after Android was started)-

http://www.scribd.com/doc/217988654/13/Boot-Loader

the Platform will be compatible with Java Platform, Micro Edition (Java ME).

Re:A performance comparison between Java and C on the Nexus 5 by mdwrigh2 on Tuesday April 15, 2014 @11:48AM (#7592432)
But they didn't intend to build a J2ME platform, but rather a shim for J2ME apps via some compatibility mode. From some of the original Google documentation:

> "Leverage Java for its existing base of developers. Build a useful app framework (not J2ME). Support J2ME apps in compatibility mode. Provide an opTMobileized JVM (Dalvik)," one slide reads.

I think there's a pretty big difference between building a platform on top of something, and planning to support it via a shim layer. At that point Android was already planning on breaking from J2ME by supporting things like JNI (which is listed on that doc but is explicitly not included in a conforming CLDC implementation for security reasons).

Besides, the only microedition APIs that are in the platform are a few khronos libs, so I really don't think any of that thought really affected Android as we know it today (which was the parents original argument). I will give you that there's more JavaME heritage than I thought, but it was thrown out pretty quickly as far as I can tell.

Re:A performance comparison between Java and C on the Nexus 5 by saosebastiao on Monday April 14, 2014 @11:28AM (#7586701)
Ive tried pointing this out before on HN and was met with a downvote army...my worst ranked post of all time IIRC. The thing is, I didnt need to see benchmarks to know iOS was significantly better. How is it not obvious to everyone else?