Skip to content

Commit dce96b9

Browse files
jasmith-hsclaude
andcommitted
Add fast-path in wrap() and fix double ThreadLocal.get() in getCurrent()
wrap() now short-circuits for String/Number/Boolean before the instanceof chain. getCurrent() was calling CURRENT_INTERPRETER.get() twice per invocation; now stores the result in a local variable. Benchmark: +62% throughput on complexTemplateBenchmark (3,316 -> 5,380 ops/s) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1b613b1 commit dce96b9

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

src/main/java/com/hubspot/jinjava/el/JinjavaInterpreterResolver.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ Object wrap(Object value) {
284284
if (value == null) {
285285
return null;
286286
}
287+
if (value instanceof String || value instanceof Number || value instanceof Boolean) {
288+
return value;
289+
}
287290
if (value instanceof PyishSerializable) {
288291
return value;
289292
}

src/main/java/com/hubspot/jinjava/interpret/JinjavaInterpreter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -981,11 +981,11 @@ public List<TemplateError> getErrorsCopy() {
981981
ThreadLocal.withInitial(Stack::new);
982982

983983
public static JinjavaInterpreter getCurrent() {
984-
if (CURRENT_INTERPRETER.get().isEmpty()) {
984+
Stack<JinjavaInterpreter> stack = CURRENT_INTERPRETER.get();
985+
if (stack.isEmpty()) {
985986
return null;
986987
}
987-
988-
return CURRENT_INTERPRETER.get().peek();
988+
return stack.peek();
989989
}
990990

991991
public static Optional<JinjavaInterpreter> getCurrentMaybe() {

0 commit comments

Comments
 (0)