[MicroPerf] Cache IL method parameter attributes during overload resolution - #20353
Open
T-Gro wants to merge 2 commits into
Open
[MicroPerf] Cache IL method parameter attributes during overload resolution#20353T-Gro wants to merge 2 commits into
T-Gro wants to merge 2 commits into
Conversation
Contributor
|
T-Gro
marked this pull request as draft
August 26, 2026 08:00
T-Gro
force-pushed
the
t-gro-overload-meta-reimport-spike
branch
5 times, most recently
from
August 26, 2026 09:18
10c2c74 to
ad39ff9
Compare
MethInfo.GetParamAttribs rebuilt the full per-parameter attribute list (custom-attr decoding, well-known-attr probes, OptionalArgInfo) from IL metadata on every call and was never cached. On an overload-heavy compile it was called 2.17M times against only 137 distinct underlying methods. Memoize the decode with the existing MemoizationTable, held per compilation via WeakMap.getOrCreate keyed on the ImportMap. The key is the method's physical ILMethodDef plus extension-member use (the C#-style extension view drops the object argument from ParamMetadata, so the two views must not share an entry); canMemoize restricts caching to monomorphic declaring types (an optional arg's default can otherwise depend on the instantiation), matching InfoReader's monomorphic-only caches. Add a regression test covering an IL extension method used with both instance and static call syntax, which shares one ILMethodDef across both views. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
T-Gro
force-pushed
the
t-gro-overload-meta-reimport-spike
branch
from
August 26, 2026 09:23
ad39ff9 to
963aa38
Compare
T-Gro
marked this pull request as ready for review
August 26, 2026 09:54
T-Gro
enabled auto-merge (squash)
August 27, 2026 08:19
abonie
reviewed
Aug 28, 2026
| let xs : System.Collections.Generic.IEnumerable<int> = Seq.ofList [ 1; 2; 3 ] | ||
| let a = xs.Select(fun x -> x + 1) |> Seq.length | ||
| let b = System.Linq.Enumerable.Select(xs, (fun x -> x + 1)) |> Seq.length | ||
| if a <> b then failwith "unexpected" |
Member
There was a problem hiding this comment.
This is a runtime check, but the test only asserts that compilation should succeed.
abonie
reviewed
Aug 28, 2026
| "ilMethodParamAttribs", | ||
| (fun (struct (ilMethInfo: ILMethInfo, m)) -> ComputeILMethodParamAttribs amap.g ilMethInfo amap m), | ||
| keyComparer = | ||
| { new IEqualityComparer<struct (ILMethInfo * range)> with |
Member
There was a problem hiding this comment.
Does dropping the range in the methods below create a risk of reporting a diagnostic with a wrong range later on?
abonie
approved these changes
Aug 28, 2026
Member
|
I'm wondering if it also improves the time 🙂 |
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.
MethInfo.GetParamAttribsdecoded a method's per-parameter attributes from IL metadata on every call and was never cached — on an overload-heavy compile that's 2.17M calls for 137 distinct methods.Memoized via the existing
MemoizationTable, held per compilation throughWeakMap.getOrCreate, keyed by the physicalILMethodDef(plus an extension-member flag, since the C#-style extension view drops the object argument). Cache stats fromfsc --times:Allocation on the workload:
ComputeILMethodParamAttribs477 MB → 0 (~810 MB total). Output byte-identical vs HEAD.