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 to the
compile_str
function that compiles an observe mini-language expression in text form to a collection ofObserverGraphs
.In testing on a medium-sided Traits-using application, this reduced the number of calls to
ObserverExpression._as_graphs
from221
to90
at application startup time.The PR also hoiks compilation of the expression provided to an
observe
decorator up a level: in code like:compilation currently (in main) occurs when
observe("foo:bar.baz")
is applied to the_some_method
function. With this PR, it occurs as part of theobserve("foo:bar:baz")
call instead. This will rarely make a difference to real code, but it does allow the possibility of sharing observe-decorators without incurring multiple compilations:Note: caching compilation of
ObserverExpressions
to graphs isn't useful: equality forObserverExpressions
is based on the conversion to graphs, so a conforming hash function would also need to be based on_as_graphs
, so would perform the exact same operation that's being cached.No tests, because there should be no perceptible change in behaviour other than performance. (Though it would make sense to develop a benchmark test suite at some point.)