This repository was archived by the owner on Nov 14, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
atlasdb-client/src/main/java/com/palantir/atlasdb/persister Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 1919import com .fasterxml .jackson .databind .ObjectMapper ;
2020import com .google .common .base .Throwables ;
2121import com .palantir .atlasdb .persist .api .ReusablePersister ;
22+ import java .io .ByteArrayInputStream ;
2223import java .io .IOException ;
24+ import java .io .StringReader ;
25+ import java .nio .charset .StandardCharsets ;
2326
2427/**
2528 * A {@link ReusablePersister} that uses an {@link ObjectMapper} to serialize and deserialize objects
@@ -38,7 +41,14 @@ public JacksonPersister(Class<T> typeRef, ObjectMapper mapper) {
3841 @ Override
3942 public final T hydrateFromBytes (byte [] input ) {
4043 try {
41- return mapper .readValue (input , typeRef );
44+ if (input .length <= 8192 && mapper .getFactory ().canUseCharArrays ()) {
45+ // Optimize to avoid allocation of heap ByteBuffer via InputStreamReader.
46+ // Remove after upgrade to Jackson 2.16.
47+ // see: https://github.com/FasterXML/jackson-core/pull/1081
48+ // and https://github.com/FasterXML/jackson-benchmarks/pull/9
49+ return mapper .readValue (new StringReader (new String (input , StandardCharsets .UTF_8 )), typeRef );
50+ }
51+ return mapper .readValue (new ByteArrayInputStream (input ), typeRef );
4252 } catch (IOException e ) {
4353 throw Throwables .propagate (e );
4454 }
You can’t perform that action at this time.
0 commit comments