Skip to content
This repository was archived by the owner on Nov 14, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Throwables;
import com.palantir.atlasdb.persist.api.ReusablePersister;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringReader;
import java.nio.charset.StandardCharsets;

/**
* A {@link ReusablePersister} that uses an {@link ObjectMapper} to serialize and deserialize objects
Expand All @@ -38,7 +41,14 @@ public JacksonPersister(Class<T> typeRef, ObjectMapper mapper) {
@Override
public final T hydrateFromBytes(byte[] input) {
try {
return mapper.readValue(input, typeRef);
if (input.length <= 8192 && mapper.getFactory().canUseCharArrays()) {
// Optimize to avoid allocation of heap ByteBuffer via InputStreamReader.
// Remove after upgrade to Jackson 2.16.
// see: https://github.com/FasterXML/jackson-core/pull/1081
// and https://github.com/FasterXML/jackson-benchmarks/pull/9
return mapper.readValue(new StringReader(new String(input, StandardCharsets.UTF_8)), typeRef);
}
return mapper.readValue(new ByteArrayInputStream(input), typeRef);
} catch (IOException e) {
throw Throwables.propagate(e);
}
Expand Down
8 changes: 8 additions & 0 deletions changelog/@unreleased/pr-6750.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type: improvement
improvement:
description: |-
Optimize to avoid allocation of heap ByteBuffer via InputStreamReader. Remove after upgrade to Jackson 2.16.

see: https://github.com/FasterXML/jackson-core/pull/1081 and https://github.com/FasterXML/jackson-benchmarks/pull/9
links:
- https://github.com/palantir/atlasdb/pull/6750