[infinispan-dev] Avoid Collections.emptySet() / emptyMap() / emptyList

David M. Lloyd david.lloyd at redhat.com
Mon Oct 22 09:40:42 EDT 2012


On 10/22/2012 01:41 AM, Galder Zamarreño wrote:
>
> On Oct 19, 2012, at 7:20 PM, David M. Lloyd <david.lloyd at redhat.com> wrote:
>
>> Also be aware that JBMAR has specific optimizations for the JDK empty
>> collections - they are represented by a single byte in the stream.
>
> Well, it's actually 3 bytes that you use to represent empty collections (at least in 1.3.15ga):
>
> write(ID_NEW_OBJECT);
> write(ID_CLASS_CLASS);
> write(classByte);
>
> Whereas with our externalizers, these get resolved via object writer (which gets called before your code to detect empty collections) and it only writes 1 byte:
>
> write(externalizerId);

No, that's inaccurate; they are singletons and do not use ID_NEW_OBJECT. 
  They're done as instances so it is one of:

     public static final int ID_EMPTY_LIST_OBJECT        = 0x5d;
     public static final int ID_EMPTY_SET_OBJECT         = 0x62;
     public static final int ID_EMPTY_MAP_OBJECT         = 0x69;

Your externalizers on the other hand take multiple bytes even in the 
simplest case.  If it is that important, you could use an ObjectResolver 
to swap in the JDK instance instead of using yet another externalizer 
(which has several bytes of overhead of its own).

-- 
- DML


More information about the infinispan-dev mailing list