Share Overload signatures behind Arc to avoid deep-copying on clone#3965
Open
alexander-beedie wants to merge 1 commit into
Open
Share Overload signatures behind Arc to avoid deep-copying on clone#3965alexander-beedie wants to merge 1 commit into
Overload signatures behind Arc to avoid deep-copying on clone#3965alexander-beedie wants to merge 1 commit into
Conversation
c068209 to
25721f9
Compare
Overload signatures behind an Arc to avoid deep-copying on cloneOverload signatures behind an Arc to avoid deep-copying on clone
Overload signatures behind an Arc to avoid deep-copying on cloneOverload signatures behind Arc to avoid deep-copying on clone
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
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.
Summary
Profiling1 showed a lot of
Typevalue churn; one of the largest drivers looked like cloningOverload, which deep-copies itsVec1<OverloadType>signature list. This happens a lot on read-only paths where nothing is mutated and the copy isn't necessary.The optimisation is just to wrap
Overload.signatureswithArc(much likeTArgsdoes). The top contributor (OverloadType::to_vec, ~23% of clone samples) then disappears from profiling.Included a dedicated
profilingentry in the Cargo.toml (basically "inherit release but keep symbols") for convenience, assuming anyone else is doing dedicated profiling builds - can remove if unwanted?I have a few other possible optimisations in mind, but want to keep any PRs single-focused/tight 👍
Test Plan
Ran the test suite; all tests show identical before/after results.
(Expected, as no type-checking logic changed).
Speedup
Overload-heavy code is what benefits;numpy(5.7% faster) andpydantic(~2.7% faster) stand out. Showing the single-threadedj1speedup here, for clarity (mtscores are noisier as the gain is small):Footnotes
On Apple Silicon M3 Max, with
--threads 1to help minimise noise. ↩