diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/impl/SizedMarshallableDataAccess.java b/src/main/java/net/openhft/chronicle/hash/serialization/impl/SizedMarshallableDataAccess.java index b83c076f4..0b52c3da4 100644 --- a/src/main/java/net/openhft/chronicle/hash/serialization/impl/SizedMarshallableDataAccess.java +++ b/src/main/java/net/openhft/chronicle/hash/serialization/impl/SizedMarshallableDataAccess.java @@ -16,8 +16,7 @@ package net.openhft.chronicle.hash.serialization.impl; -import net.openhft.chronicle.bytes.Bytes; -import net.openhft.chronicle.bytes.RandomDataInput; +import net.openhft.chronicle.bytes.*; import net.openhft.chronicle.hash.Data; import net.openhft.chronicle.hash.serialization.DataAccess; import net.openhft.chronicle.hash.serialization.SizedReader; @@ -36,8 +35,11 @@ public class SizedMarshallableDataAccess extends InstanceCreatingMarshaller sizedReader; private SizedWriter sizedWriter; - /** Cache field */ + // Cache fields + private transient boolean bytesInit; private transient Bytes bytes; + private transient long size; + private transient VanillaBytes targetBytes; /** State field */ private transient T instance; @@ -60,10 +62,16 @@ public class SizedMarshallableDataAccess extends InstanceCreatingMarshaller extends InstanceCreatingMarshaller extends InstanceCreatingMarshaller getData(@NotNull T instance) { this.instance = instance; - bytes.clear(); - sizedWriter.write(bytes, sizedWriter.size(instance), instance); + this.size = sizedWriter.size(instance); + bytesInit = false; return this; } diff --git a/src/main/java/net/openhft/chronicle/map/impl/stage/entry/MapEntryStages.java b/src/main/java/net/openhft/chronicle/map/impl/stage/entry/MapEntryStages.java index f9ba6be6d..78fec2353 100644 --- a/src/main/java/net/openhft/chronicle/map/impl/stage/entry/MapEntryStages.java +++ b/src/main/java/net/openhft/chronicle/map/impl/stage/entry/MapEntryStages.java @@ -93,11 +93,13 @@ public abstract class MapEntryStages extends HashEntryStages // the off-heap bytes. This condition avoids in-place data copy. // TODO would be nice to reduce scope of this check, i. e. check only when it could be // true, and avoid when it surely false (fresh value put, relocating put etc.) - RandomDataInput valueBytes = value.bytes(); - if (valueBytes instanceof NativeBytesStore && - valueBytes.address(value.offset()) == s.segmentBS.address(valueOffset)) { - return; - } + // TODO this optimization is now disabled, because it calls value.bytes() that forces double + // data copy, if sizedReader/Writer configured for the value. +// RandomDataInput valueBytes = value.bytes(); +// if (valueBytes instanceof NativeBytesStore && +// valueBytes.address(value.offset()) == s.segmentBS.address(valueOffset)) { +// return; +// } value.writeTo(s.segmentBS, valueOffset); }