Home » Author Archives: Peter Lawrey (page 5)

Author Archives: Peter Lawrey

Local variables inside a loop and performance

java-logo

Overview Sometimes a question comes up about how much work allocating a new local variable takes.  My feeling has always been that the code becomes optimised to the point where this cost is static i.e. done once, not each time the code is run. Recently Ishwor Gurung suggested considering moving some local variables outside a loop. I suspected it wouldn’t ...

Read More »

Can synchronization be optimised away?

java-logo

Overview There is a common misconception that because the JIT is smart and synchronization can be eliminated for an object which is only local to a method that there is no performance impact.             A test comparing StringBuffer and StringBuilder These two classes do basically the same thing except one is synchronized (StringBuffer) and the ...

Read More »

Java Object resurrection

java-logo

Overview After an object which overrides finalize() is collected it is added to a finalization queue to be cleaned up after calling the finalize() method of each object.  By what happens if you resurrect the object?             When is finalize called? The finalize method is called by a single threaded system task which calls this ...

Read More »

Performance of inlined virtual method invocations in Java

java-logo

Overview One of the benefits of dynamic compilation it the ability to support extensive method inlining on virtual method code. While inlining the code improves performance, the code still has to check the type (in case it has changed since it was optimised) or select between multiple possible implementations. This leads to the question; how does having multiple implementations of ...

Read More »

When using direct memory can be faster

java-logo

Overview Using direct memory is no guarantee of improving performance.  Given it adds complexity, it should be avoided unless you have a compelling reason to use it. This excellent article by Sergio Oliveira Jr shows its not simply a matter of using direct memory to improve performance Which one is faster: Java heap or native memory? Where direct memory and memory mapped files ...

Read More »

Wasting time by saving memory

software-development-2-logo

You might say that at my company, the hard ware is 10x more expensive, but it also likely you time is costing the company about the same more. In any case, this article attempts to demonstate that there is a tipping point where it no longer makes sense to spend time saving memory, or even thinking about it.     ...

Read More »

Java Intrinsics and Performance

java-logo

The original question was How to count the number of 1’s a number will have in binary? I included a performance comparison of using Integer.bitCount() which can be turned into an intrinic i.e. a single machine code instruction POPCNT and the Java code which does the same thing. Question How do I count the number of 1’s a number will ...

Read More »

Java Hidden code

java-logo

Sometime ago I came across the issue of invisible characters in Strings. These can really cause confusion because they are invisible. String a = "Hello\u200e"; String b = "Hello\u200f"; System.out.println('\'' + a + "' and '" + b + "' are length " + a.length() + " and " + b.length() + ", equals() is " + a.equals(b)); prints 'Hello?' ...

Read More »

Java memes which refuse to die

java-logo

Also titled; My pet hates in Java coding.  There are a number of Java memes which annoy me, partly because they were always a bad idea, but mostly because people still keep picking them up years after there is better alternatives. Using StringBuffer instead of StringBuilder The Javadoc for StringBuffer from 2004 states As of release JDK 5, this class ...

Read More »

Odd practices in Java

java-logo

Overview There are a number of practices in Java which oddly baffle me. Here are but a few. Using -Xmx and -Xms The option -Xmx is widely used to set the maximum memory size. As noted in the Java HotSpot VM Options Options that begin with -X are non-standard (not guaranteed to be supported on all VM implementations), and are ...

Read More »
Do you want to know how to develop your skillset and become a ...

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!
Get ready to Rock!
To download the books, please verify your email address by following the instructions found on the email we just sent you.

THANK YOU!

Close