馃憣 Performance: Memoize Inline parser for build_need
#968
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.
As discussed in #967,
build_need
(called fromprint_need_nodes
) is currently taking a large amount of build times.A key reason for this is that the initialisation of the inline parser, which requires compiling numerous regexes, is being run on every call.
This is not required, since the initialisation is invariant.
In this PR therefore, we move the initialisation to a cached function, which will only run once per build.
As shown when using
phinx-analysis --project needs --pyinstrument --tree --tree-filter 0.01
, compared to #967, this significantly reduces theprint_need_nodes
component of the build time; from taking ~25% to ~8%In this example it reduces the total build time from ~1.6 seconds to ~1.2 seconds