Index: oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.java =================================================================== --- oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.java (revision 1731857) +++ oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.java (working copy) @@ -109,7 +109,7 @@ * Cache of recently stored template records, used to avoid storing * duplicates of frequently occurring data. */ - final Map templateCache = newItemsCache(TPL_RECORDS_CACHE_SIZE); + final Map templateCache = newItemsCache(TPL_RECORDS_CACHE_SIZE); private static final Map newItemsCache(final int size) { final boolean disabled = size <= 0; @@ -589,10 +589,10 @@ } } - public RecordId writeTemplate(Template template) throws IOException { + private RecordId writeTemplate(Template template) throws IOException { checkNotNull(template); - RecordId id = templateCache.get(template); + RecordId id = templateCache.get(template.hash()); if (id != null) { return id; // shortcut if the same template was recently stored } @@ -663,7 +663,7 @@ RecordId tid = writeRecord(newTemplateWriter(ids, propertyNames, propertyTypes, head, primaryId, mixinIds, childNameId, propNamesId, version)); - templateCache.put(template, tid); + templateCache.put(template.hash(), tid); return tid; } Index: oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java =================================================================== --- oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java (revision 1731857) +++ oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java (working copy) @@ -32,8 +32,14 @@ import javax.annotation.Nonnull; import com.google.common.base.Objects; +import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; import com.google.common.collect.Lists; +import com.google.common.hash.Funnel; +import com.google.common.hash.Hashing; +import com.google.common.hash.PrimitiveSink; +import org.apache.commons.io.Charsets; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Type; import org.apache.jackrabbit.oak.plugins.memory.MemoryChildNodeEntry; @@ -48,6 +54,55 @@ */ public class Template { + private static final Funnel