Cut call time of add_prefix()
by 99.8%
#69
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.
Fix: #68
Previously on perf hunting: we had stumbled across a method in the wild that seemed harmless enough, but upon getting closer it turned to attack and we saw that it was in fact O(2n^2) in disguise!!
On this episode: we propose a function-neutral change that looks the same to an external observer (eg. someone that calls and of the public methods
combine()
,prefixes()
, ornamespaces()
methods directly) but internally within theadd_prefix
method we avoid set comprehensions that become very expensive as thenamespaces
orprefixes
sets become large.For
Run on the
linkmltests
--with-slow` enabled, no tests fail and...Current version: 156s (cumulative), 0.00580s per call
This PR: 0.2s (cumulative), 7.75e-06s per call
Change: -155.2s, 99.8% decrease