Repository navigation
Build literal kwargs once at compile time - #1061
Merged
Keats merged 1 commit intoNov 20, 2026
Merged
Conversation
When every argument of a filter, test or function call is a literal, the kwargs map is the same on every call. Emit it as a single constant instead of rebuilding it each time the call runs.
patrick-immometrica
marked this pull request as ready for review
November 15, 2026 19:26
Owner
|
Thanks! |
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.
When a filter, test or function is called with arguments, the VM builds the kwargs map on every call: keys and values are pushed, then
BuildMapcollects them into a temporaryVec, turns each key into anArc<str>, builds the map and wraps it in anArc. That's four allocations for something liketruncate(length=10), repeated on every loop iteration although the result is always the same.If every argument is a literal, the compiler now builds the map itself and emits a single
LoadConst, like the parser already does for literal maps and arrays. A call with at least one non-literal argument compiles exactly as before, and so does a call without arguments (those already share one empty map).Kwargsonly hands out references, so sharing the map between calls isn't observable from a filter.Numbers for this template over 100 products (release build, counting global allocator, time is the best of three interleaved runs):
Templates without literal kwargs have the same allocation counts as before and the output is byte-identical everywhere I compared it.
The two compiler snapshots that changed are the ones calling a filter with
lang="fr". I added one more input with a literal, a non-literal and a mixed call next to each other.