Feeds

Time to overcome Java misconceptions

Program, profile, repeat

Top 5 reasons to deploy VMware with Tegile

Myths and legends It doesn't really matter which version of the Java platform you use, does it? Well I know for sure that thread context switching is expensive. Isn't it? OK, but there's no doubt that 32-bit Java Virtual Machines (JVMs) are faster than 64-bit JVMs. Right?

The truth is, most of the things we think we know about Java performance are actually pretty hard to quantify. That's the conclusion Google engineers Jeremy Manson and Paul Tyma have come to through what they humbly describe as "an unending search for the truth".

"We had been writing a lot of code - server code, fast code, Java code, C++ code - and we realized one day that there are a lot of myths out there about Java performance, beliefs that we just knew weren't true, but had never been tested," Manson said at this Spring's Software Development West.

"We came to see that these unexamined beliefs actually make everybody's life more difficult," Tyma added. "They make you write lousy, broken code, because you're working around something that might not even be true. And then your code becomes unreadable."

Not precisely myth-busters, Manson and Tyma took on the roles of assumption challengers and shared their insights with SD West attendees, during a joint preso that touched on some timeless themes.

"This isn't about optimizing your code," Manson said. "It's about challenging those assumptions you make while you're writing it."

And what are those assumptions?

Number one: versions don't matter.

"A lot of people think that they can keep on using 1.4 forever, and it won't affect performance," Tyma said. "Well, it turns out they've been improving Java steadily over the past 13 years, and 1.6 is a lot faster than 1.5, and 1.5 is a lot faster than 1.4. And remember, you can run 1.4 byte code on 1.6 VMs."

Number two: 64-bit code is slower than 32-bit code.

"I've heard this from a lot of people," Manson said. "And the reason those people seem absolutely convinced of this is that the pointers are twice as large, and all of a sudden you're taking up between one and two megs of memory... and now that you're using more memory, your code isn't going to fit into the L1 and L2 cache, which will slow down your code."

But this scenario doesn't always manifest in the x86 world, he said, because 64-bit code has twice as many registers, so there's less register spillage, and you can have longer pipelines in your processor. So code that is very intensive in terms of registers and integer performance can be a lot faster in 64-bit.

Number three: thread context switching is expensive.

In the Linux 2.6 NPTL library, which is where Tyma and Manson ran their tests, context switching was not expensive at all. Even with a thousand threads competing for Core Duo CPU cycles, the context-switching wasn't even noticeable.

Number four: locking is expensive.

If they're uncontended, no. Uncontended synchronization is cheap, and can even be free. Add a thread, and that picture changes. Synchronized locking with contention gets more expensive; the cost goes up significantly. But increase the number of threads, and the cost doesn't change much after that, Tyma noted. "So yes, contended synchronization does cost more, but [that cost] doesn't tend to scale," he said.

"The moral here," said Manson, "is don't avoid synchronization. When doing tricky things to avoid synchronization, you end up writing really bad code."

So what's Tyma and Manson's bottom-line advice to developers seeking to write faster Java code? "If you want your code to be faster, don't waste your time trying to take advantage of any of these kinds of performance myths," Manson said. "Just write the best code you can. Profile it to find the bottlenecks. Remove the bottlenecks. Rinse and repeat."

You can read Manson's summarized takeaways here. ®

Top 5 reasons to deploy VMware with Tegile

More from The Register

next story
That dreaded syncing feeling: Will Microsoft EVER fix OneDrive?
Microsoft's long history of broken Windows sync
Mozilla, EFF, Cisco back free-as-in-FREE-BEER SSL cert authority
Let’s Encrypt to give HTTPS-everywhere a boost in 2015
Bada-Bing! Mozilla flips Firefox to YAHOO! for search
Microsoft system will be the default for browser in US until 2020
SLURP! Flick your TONGUE around our LOLLIPOP – Google
Android 5 is coming – IF you're lucky enough to have the right gadget
Nokia's N1 fondleslab's HIDDEN BRILLIANCE: The 'Z Launcher'
Sugarcoating Android's Lollipop makes tab easier to swallow
Bug fixes! Get your APPLE BUG FIXES! iOS and OS X updates right here!
Yosemite fixes Wi-Fi hiccup, older iOS devices get performance boost
Microsoft: Your Linux Docker containers are now OURS to command
New tool lets admins wrangle Linux apps from Windows
Facebook, working on Facebook at Work, works on Facebook. At Work
You don't want your cat or drunk pics at the office
Soz, web devs: Google snatches its Wallet off the table
Killing off web service in 3 months... but app-happy bonkers are fine
prev story

Whitepapers

Choosing cloud Backup services
Demystify how you can address your data protection needs in your small- to medium-sized business and select the best online backup service to meet your needs.
A strategic approach to identity relationship management
ForgeRock commissioned Forrester to evaluate companies’ IAM practices and requirements when it comes to customer-facing scenarios versus employee-facing ones.
High Performance for All
While HPC is not new, it has traditionally been seen as a specialist area – is it now geared up to meet more mainstream requirements?
Mitigating web security risk with SSL certificates
Web-based systems are essential tools for running business processes and delivering services to customers.
Intelligent flash storage arrays
Tegile Intelligent Storage Arrays with IntelliFlash helps IT boost storage utilization and effciency while delivering unmatched storage savings and performance.