|
74 | 74 | import java.util.TreeMap; |
75 | 75 |
|
76 | 76 | import static com.fasterxml.jackson.core.JsonFactory.Feature.CANONICALIZE_FIELD_NAMES; |
| 77 | +import static com.fasterxml.jackson.core.JsonFactory.Feature.INTERN_FIELD_NAMES; |
77 | 78 | import static com.fasterxml.jackson.core.JsonToken.END_ARRAY; |
78 | 79 | import static com.fasterxml.jackson.core.JsonToken.END_OBJECT; |
79 | 80 | import static com.fasterxml.jackson.core.JsonToken.FIELD_NAME; |
@@ -121,7 +122,22 @@ private JsonUtil() {} |
121 | 122 | // Note: JsonFactory is mutable, instances cannot be shared openly. |
122 | 123 | public static JsonFactory createJsonFactory() |
123 | 124 | { |
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(); |
125 | 141 | } |
126 | 142 |
|
127 | 143 | public static JsonParser createJsonParser(JsonFactory factory, Slice json) |
|
0 commit comments