Skip to content

Commit 90743b4

Browse files
committed
Disable INTERN_FIELD_NAMES to reduce contention during JSON decoding
1 parent f52f579 commit 90743b4

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

client/trino-client/src/main/java/io/trino/client/TrinoJsonCodec.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.lang.reflect.Type;
3333
import java.util.function.Supplier;
3434

35+
import static com.fasterxml.jackson.core.JsonFactory.Feature.INTERN_FIELD_NAMES;
3536
import static com.google.common.base.Preconditions.checkArgument;
3637
import static java.util.Objects.requireNonNull;
3738

@@ -40,6 +41,19 @@ public class TrinoJsonCodec<T>
4041
// copy of https://github.com/airlift/airlift/blob/master/json/src/main/java/io/airlift/json/ObjectMapperProvider.java
4142
static final Supplier<ObjectMapper> OBJECT_MAPPER_SUPPLIER = () -> {
4243
JsonFactory jsonFactory = JsonFactory.builder()
44+
/*
45+
* When multiple threads deserialize JSON responses concurrently,
46+
* Jackson's default behavior of interning field names causes severe lock contention
47+
* on the JVM's global String pool. This manifests as threads blocked waiting at
48+
* {@code InternCache.intern()}.
49+
*
50+
* Disabling INTERN_FIELD_NAMES eliminates this contention with minimal performance
51+
* impact - field name deduplication becomes slightly less memory-efficient, but the
52+
* elimination of lock contention far outweighs this cost in high-concurrency scenarios.
53+
*
54+
* @see <a href="https://github.com/FasterXML/jackson-core/issues/332">Jackson issue on InternCache contention</a>
55+
*/
56+
.disable(INTERN_FIELD_NAMES)
4357
.streamReadConstraints(StreamReadConstraints.builder()
4458
.maxStringLength(Integer.MAX_VALUE)
4559
.maxNestingDepth(Integer.MAX_VALUE)

core/trino-main/src/main/java/io/trino/util/JsonUtil.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
import java.util.TreeMap;
7575

7676
import static com.fasterxml.jackson.core.JsonFactory.Feature.CANONICALIZE_FIELD_NAMES;
77+
import static com.fasterxml.jackson.core.JsonFactory.Feature.INTERN_FIELD_NAMES;
7778
import static com.fasterxml.jackson.core.JsonToken.END_ARRAY;
7879
import static com.fasterxml.jackson.core.JsonToken.END_OBJECT;
7980
import static com.fasterxml.jackson.core.JsonToken.FIELD_NAME;
@@ -121,7 +122,22 @@ private JsonUtil() {}
121122
// Note: JsonFactory is mutable, instances cannot be shared openly.
122123
public static JsonFactory createJsonFactory()
123124
{
124-
return jsonFactoryBuilder().disable(CANONICALIZE_FIELD_NAMES).build();
125+
return jsonFactoryBuilder()
126+
.disable(CANONICALIZE_FIELD_NAMES)
127+
/*
128+
* When multiple threads deserialize JSON responses concurrently,
129+
* Jackson's default behavior of interning field names causes severe lock contention
130+
* on the JVM's global String pool. This manifests as threads blocked waiting at
131+
* {@code InternCache.intern()}.
132+
*
133+
* Disabling INTERN_FIELD_NAMES eliminates this contention with minimal performance
134+
* impact - field name deduplication becomes slightly less memory-efficient, but the
135+
* elimination of lock contention far outweighs this cost in high-concurrency scenarios.
136+
*
137+
* @see <a href="https://github.com/FasterXML/jackson-core/issues/332">Jackson issue on InternCache contention</a>
138+
*/
139+
.disable(INTERN_FIELD_NAMES)
140+
.build();
125141
}
126142

127143
public static JsonParser createJsonParser(JsonFactory factory, Slice json)

0 commit comments

Comments
 (0)