You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Perf: Tokenizer rebuilds operator/literal tries on every instantiation #866
The operators and literalValues inputs are identical across all tokenizer instances for a given Liquid engine. In scenarios where many short template strings are parsed in a single pass (e.g. validating hundreds of {{ variable }} expressions in a document), this creates significant overhead from redundant trie construction.
Profiling data
We're using LiquidJS (v10.25.0) inside Kibana's workflow YAML editor to validate Liquid template expressions on every keystroke. For a large document (~1,500 lines, ~360 template variables), CPU profiling shows:
We already cache parse() results (LRU by template string), which helps on cache hits. But on cache misses, createTrie is the dominant cost inside the tokenizer — more expensive than the actual tokenization work.
Suggested fix
Cache the tries at the Liquid engine level (or Parser level) and pass them into Tokenizer instances, since the operator set and literal values don't change after engine construction:
// In Parser or Liquid engine — build oncethis.opTrie=createTrie(this.options.operators);this.literalTrie=createTrie(literalValues);// In Tokenizer constructor — reuseconstructor(input,opTrie,literalTrie,file,range){this.opTrie=opTrie;this.literalTrie=literalTrie;// ...}
This would be a non-breaking internal change. The Tokenizer constructor isn't part of the public API contract (users go through Liquid.parse()).
This is an ancient feature allowing customized operators which turns out to not make much sense. Let's plan remove it in v11 and make the trie a constant.
Activity
harttle commentedon Apr 3, 2026
This is an ancient feature allowing customized operators which turns out to not make much sense. Let's plan remove it in v11 and make the trie a constant.