Merged
Conversation
- Add enableFilterChainOptimization config option to JinjavaConfig (defaults to false) - Modify ExtendedParser to conditionally use AstFilterChain based on config - Override shouldUseFilterChainOptimization() in EagerExtendedParser to always return false - Remove EagerAstFilterChain.java as eager mode now uses old nested method approach - Revert test files to expect old format for eager execution
- Add AstFilterChainPerformanceTest to verify optimization performance - Tests verify both approaches produce identical results - Includes manual benchmark test (ignored by default) for detailed comparison - Automated test verifies optimized version is faster than unoptimized (at least 5% improvement) - Uses nested property access (content.text) to better simulate real-world usage
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
jasmith-hs
reviewed
Jan 12, 2026
| private ExecutionMode executionMode = DefaultExecutionMode.instance(); | ||
| private LegacyOverrides legacyOverrides = LegacyOverrides.NONE; | ||
| private boolean enablePreciseDivideFilter = false; | ||
| private boolean enableFilterChainOptimization = false; |
Contributor
There was a problem hiding this comment.
Do all the tests pass if this is set to true?
Collaborator
Author
There was a problem hiding this comment.
yes, just did it.
jasmith-hs
reviewed
Jan 12, 2026
Comment on lines
+69
to
+70
| String filterKey = ExtendedParser.FILTER_PREFIX + spec.getName(); | ||
| interpreter.getContext().addResolvedValue(filterKey); |
Contributor
There was a problem hiding this comment.
This should be tested for parity with regular filter parsing and evaluation
Comment on lines
173
to
180
| builder.append('('); | ||
| for (int i = 0; i < params.getCardinality(); i++) { | ||
| if (i > 0) { | ||
| builder.append(", "); | ||
| } | ||
| params.getChild(i).appendStructure(builder, bindings); | ||
| } | ||
| builder.append(')'); |
Contributor
There was a problem hiding this comment.
Suggested change
| builder.append('('); | |
| for (int i = 0; i < params.getCardinality(); i++) { | |
| if (i > 0) { | |
| builder.append(", "); | |
| } | |
| params.getChild(i).appendStructure(builder, bindings); | |
| } | |
| builder.append(')'); | |
| params.appendStructure(builder, bindings); |
| * Run with: mvn test -Dtest=AstFilterChainPerformanceTest | ||
| * Or run the main() method directly for more detailed output. | ||
| */ | ||
| public class AstFilterChainPerformanceTest { |
Contributor
There was a problem hiding this comment.
Unit tests should be made separate from performance tests
…handling The parity test ensures the optimized filter chain produces identical results to the unoptimized nested method approach across many scenarios including chained filters, named parameters, SafeString handling, and edge cases. Fixed a behavioral difference where unknown filters would pass through the original value in the optimized path but return empty in the unoptimized path. Now both paths return null for unknown filters. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Moved unit tests to AstFilterChainTest.java, keeping only performance-related tests in AstFilterChainPerformanceTest.java for clearer test organization. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Use params.appendStructure() instead of manually iterating through children, reducing code duplication. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Collaborator
Author
|
@jasmith-hs can you take another look? |
jasmith-hs
approved these changes
Jan 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces an optimization for chained filter expressions in Jinjava templates. Instead of creating deeply nested AST nodes for expressions like
{{ foo|filter1|filter2|filter3 }}, a flattenedAstFilterChainnode is used, which improves performance by reducing recursive call overhead.Key changes:
AstFilterChainclass that processes filters iteratively instead of recursivelyFilterSpecclass to represent individual filter specifications in the chainenableFilterChainOptimizationin JinjavaConfig (defaults to false)EagerExtendedParseroverrides the config to always use the traditional nested approachTest plan
AstFilterChainPerformanceTestto verify both approaches produce identical results