Cache the result of the compile_expr function #1528
Merged
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.
This PR adds an LRU cache for the
compile_expr
function, to eliminate unnecessary calls to_as_graph
. I also made a one-line change in theobserve
function so that all expression compilation goes throughcompile_expr
.I've also boosted the size of the three parsing-related caches from 128 entries to 256.
I opted not to do a per-Expression-object caching of the result of the
_as_graphs
call (as suggested in the #1516 discussion); it adds extra complication in that it makes theExpression
objects mutable, and so introduces potential thread-safety concerns; in contrast,lru_cache
has thread-safety provisions built in. There's benefit in keeping theExpression
objects as simple immutable pure data structures - I'd rather not change that unless there's clear evidence that it's beneficial performance-wise.No test changes or additions, because there are no observable behaviour changes.
Closes #1510
See also #1516, #1517