Skip to content

Commit d746aca

Browse files
jasmith-hsclaude
andcommitted
Skip Jackson serialization for primitives in PyishObjectMapper
In 3.0, LegacyOverrides.THREE_POINT_0 defaults usePyishObjectMapper=true, causing every expression output to go through full Jackson ObjectWriter serialization. For String/Number/Boolean (the vast majority of expression results), this is unnecessary -- val.toString() produces the same output. This was the single largest source of the 3.0 vs 2.8.x regression. Benchmark: +104% throughput on complexTemplateBenchmark (3,316 -> 6,772 ops/s) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent fad3d39 commit d746aca

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/main/java/com/hubspot/jinjava/objects/serialization/PyishObjectMapper.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,13 @@ private static ObjectMapper getPyishObjectMapper() {
5757
}
5858

5959
public static String getAsUnquotedPyishString(Object val) {
60-
if (val != null) {
61-
return WhitespaceUtils.unquoteAndUnescape(getAsPyishString(val, true));
60+
if (val == null) {
61+
return "";
6262
}
63-
return "";
63+
if (val instanceof String || val instanceof Number || val instanceof Boolean) {
64+
return val.toString();
65+
}
66+
return WhitespaceUtils.unquoteAndUnescape(getAsPyishString(val, true));
6467
}
6568

6669
public static String getAsPyishString(Object val) {

0 commit comments

Comments
 (0)