Skip to content

Commit

Permalink
Remove Jackson byte[] workaround
Browse files Browse the repository at this point in the history
Now that AtlasDB has upgraded to Jackson 2.16.1, remove performance
workaround that landed upstream in Jackson 2.16.0. See
FasterXML/jackson-core#1081
  • Loading branch information
schlosna committed Jun 27, 2024
1 parent b291ed8 commit acf3d58
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
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 @@ -41,14 +38,7 @@ public JacksonPersister(Class<T> typeRef, ObjectMapper mapper) {
@Override
public final T hydrateFromBytes(byte[] input) {
try {
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);
return mapper.readValue(input, typeRef);
} catch (IOException e) {
throw Throwables.propagate(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
import com.palantir.conjure.java.serialization.ObjectMappers;
import com.palantir.logsafe.SafeArg;
import com.palantir.logsafe.exceptions.SafeIllegalStateException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringReader;
import java.nio.charset.StandardCharsets;
import java.util.Optional;
import java.util.function.Function;

Expand Down Expand Up @@ -101,15 +98,7 @@ static VersionedInternalSchemaMetadata encode(InternalSchemaMetadata internalSch

private static InternalSchemaMetadata decodeViaJson(byte[] byteArray) {
try {
if (byteArray.length <= 8192) {
// 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 SCHEMA_METADATA_READER.readValue(
new StringReader(new String(byteArray, StandardCharsets.UTF_8)));
}
return SCHEMA_METADATA_READER.readValue(new ByteArrayInputStream(byteArray));
return SCHEMA_METADATA_READER.readValue(byteArray);
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down

0 comments on commit acf3d58

Please sign in to comment.