Improving performance with null rather than default values?

They say that premature optimization is the root of all evil, but here it goes ...

We have a high-performance application; in-memory cache supported by Java on the server side and what should be a very fast client-side C # GUI.

I note that currently the objects that we use in the cache have default values ​​- for example. initializing the default strings "and" Dates "to 1/1/1999, and not leaving them zero.

Now I can be very thin here, but does this add a little more space to one object (both in the cache and when the object becomes serialized) than otherwise if it were null?

It’s just interesting what kind of improvement (if any) would have happened when our volumes of objects began to become quite high ...

Cheers, Dave.

+3
source share
1 answer

Premature optimization is definitely evil.

But thinking about the performance characteristics of your application and the appropriate design strategies for optimizing performance is quite reasonable if performance is a key requirement of the application :-)

A few relevant points:

  • () null, . , . , , L1, , .
  • , , , - , ( ), .
  • , singleton, , :
    • , "" ( String.intern()!)
    • , ,
    • (value == DEFAULT_SINGLETON) , , DEFAULT_SINGLETON .
  • singleton, , - . , . - readResolve() .., , .

, , , null .

  • , ( NullPointerException , ).
+3

All Articles