Repository navigation
checker: check nested overloaded calls in linear time - #1010
Merged
Merged
Conversation
An overloaded function, such as the replace, join or sort builtins, checks its arguments once per overload it tries. Nested calls multiplied this at every level, so compile time grew exponentially with nesting depth: 42 nested replace calls never finished compiling. While overloads are being tried, cache the natures of call and builtin nodes for the rest of the pass, so trying the next overload doesn't check them again. The cache is cleared on reset, at the start of every pass. Fixes #1008
|
Thanks for the immediate fix! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #1008.
An overloaded function, such as the
replace,joinorsortbuiltins, checks its arguments once per overload it tries. Nested calls multiplied this at every level, so compile time grew exponentially with nesting depth. A short expression of 42 nestedreplacecalls never finished compiling. Functions registered throughexpr.Functionwith several overloads were affected too when they returnany.While overloads are being tried, the checker now caches the natures of call and builtin nodes for the rest of the pass, so trying the next overload doesn't check them again. The cache is cleared on reset, at the start of every pass, so it can't go stale after patchers change the tree. Expressions without overloaded calls don't touch it.
replacebeforeBenchmarks against master (8 interleaved runs, benchstat):
BenchmarkCheckerunchanged within noise, 0 allocations. Compiling expressions that use builtins is 7–11% faster, with up to 11% fewer allocations.test/issues/1008compiles depth-100 nesting in four shapes. It hangs without the fix.