Skip to content

Commit fdee70e

Browse files
janakdrCopybara-Service
authored and
Copybara-Service
committed
Make DynamicCodec always memoize. Since it replaces Java serialization, which memoizes, we should too.
PiperOrigin-RevId: 191813677
1 parent 538e5c6 commit fdee70e

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/main/java/com/google/devtools/build/lib/skyframe/serialization/DynamicCodec.java

+7
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public MemoizationStrategy getStrategy() {
5858
@Override
5959
public void serialize(SerializationContext context, Object obj, CodedOutputStream codedOut)
6060
throws SerializationException, IOException {
61+
// TODO(janakr,shahan): Remove when memoization is on by default.
62+
context = context.getMemoizingContext();
6163
for (Map.Entry<Field, Long> entry : offsets.entrySet()) {
6264
serializeField(context, codedOut, obj, entry.getKey().getType(), entry.getValue());
6365
}
@@ -135,6 +137,11 @@ public Object deserialize(DeserializationContext context, CodedInputStream coded
135137
throw new SerializationException("Could not instantiate object of type: " + type, e);
136138
}
137139
context.registerInitialValue(instance);
140+
// We start memoizing if we weren't already doing so. We can't start before registering the
141+
// initial value because the memoizer would get confused, since it doesn't have a tag for this
142+
// object.
143+
// TODO(janakr,shahan): Remove when memoization is on by default.
144+
context = context.getMemoizingContext();
138145
for (Map.Entry<Field, Long> entry : offsets.entrySet()) {
139146
deserializeField(context, codedIn, instance, entry.getKey().getType(), entry.getValue());
140147
}

src/test/java/com/google/devtools/build/lib/skyframe/serialization/DynamicCodecTest.java

-2
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ public void testArray() throws Exception {
228228
new char[] {'a', 'b', 'c', 'x', 'y', 'z'},
229229
new long[] {Long.MAX_VALUE, Long.MIN_VALUE, 27983741982341L, 52893748523495834L}))
230230
.addCodec(new DynamicCodec(ArrayExample.class))
231-
.makeMemoizing()
232231
.runTests();
233232
}
234233

@@ -262,7 +261,6 @@ public void testNestedArray() throws Exception {
262261
}),
263262
new NestedArrayExample(new int[][] {{1, 2, 3}, null, {7}}))
264263
.addCodec(new DynamicCodec(NestedArrayExample.class))
265-
.makeMemoizing()
266264
.runTests();
267265
}
268266

0 commit comments

Comments
 (0)