Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

perf: skip redundant IWSAM method filtering and cache FSharpSymbol wrappers - #20985

Open
shayanhabibi wants to merge 1 commit into
dotnet:mainfrom
shayanhabibi:pr/up-02-symbol-and-iwsam-allocs
Open

shayanhabibi wants to merge 1 commit into
dotnet:mainfrom
shayanhabibi:pr/up-02-symbol-and-iwsam-allocs

Conversation

@shayanhabibi

Copy link
Copy Markdown

Description

Hot symbol-inspection and interface-checking paths repeat work on immutable checked symbols and re-filter inheritance hierarchies eagerly:

  1. Lazy IWSAM hierarchy filtering (InfoReader.HasIntrinsicStaticAbstractMethod, CheckExpressions.CheckIWSAM): CheckIWSAM previously materialized and filtered all intrinsic method sets (FilterOverridesOfMethInfos / ExcludeHiddenOfMethInfosImpl) even when no raw method in the interface hierarchy was a static abstract slot. HasIntrinsicStaticAbstractMethod checks raw method sets first and skips override/hiding passes when no candidate exists.
  2. Non-allocating ccuOfTyconRef (TypedTreeBasics.fs): Uses if eref.IsLocalRef then None else Some eref.nlr.Ccu instead of matching active patterns | ERefLocal | ERefNonLocal |, avoiding intermediate Choice allocations per call.
  3. FSharpSymbol wrapper caching (Symbols.fs): Memoizes FSharpMemberOrFunctionOrValue.CurriedParameterGroups (curriedParameterGroups mutable field) and FSharpType.GenericArguments (genericArguments mutable field), and fast-paths IsAbbreviation checks to eliminate repeated list/wrapper allocations across symbol inspection passes.

Summary of Changes & Cost/Benefit

  • Modified (src/): src/Compiler/Checking/Expressions/CheckExpressions.fs, src/Compiler/Checking/InfoReader.fs, src/Compiler/Checking/InfoReader.fsi, src/Compiler/Symbols/Symbols.fs, src/Compiler/TypedTree/TypedTreeBasics.fs (0 public .bsl changes).
  • Tests & Benchmarks: tests/FSharp.Compiler.Service.Tests/Symbols.fs (SymbolWrapperCaching), tests/benchmarks/FCSBenchmarks/CompilerServiceBenchmarks/SymbolAndIwsamBenchmarks.fs, FSharp.Compiler.Benchmarks.fsproj, README.md, 11.0.200.md (10 files changed, +330 / -41).
  • Benefit: -47.4% latency and -56.9% allocation on repeated parameter/type wrapper inspection (InspectSymbolsRepeatedly), and -8.1% allocation on WarmCheckFileWithInterfaces (0 FS3261 warnings).
  • Cost / Trade-off: Adds cached mutable reference fields on FSharpMemberOrFunctionOrValue and FSharpType wrapper instances.

Benchmarks

Measured against dotnet/main @ 59c747725e (BenchmarkDotNet v0.13.10, .NET 11.0.0, Windows 11, AMD Ryzen 9 9900X, WarmupCount=3, IterationCount=10, command: dotnet run -c Release --no-build -- --filter *SymbolAndIwsamBenchmarks* --warmupCount 3 --iterationCount 10):

Benchmark Side Mean Error StdDev Gen0 Gen1 Allocated
InspectSymbolsRepeatedly (60 fns, 3 passes) Baseline 59c747725e 610.7 μs 16.73 μs 11.06 μs 41.0156 - 2.39 MB
InspectSymbolsRepeatedly (60 fns, 3 passes) PR 321.2 μs 10.03 μs 6.63 μs 11.2305 - 1.03 MB
WarmCheckFileWithInterfaces (60 fns, CheckIWSAM) Baseline 59c747725e 58,814.4 μs 8,284.45 μs 4,332.93 μs 500.0000 250.0000 58.83 MB
WarmCheckFileWithInterfaces (60 fns, CheckIWSAM) PR 67,968.3 μs 17,116.39 μs 11,321.43 μs 500.0000 250.0000 54.04 MB

(Note: on WarmCheckFileWithInterfaces, 99.9% CIs overlap [50.5, 67.1] ms vs [50.9, 85.1] ms due to Tier-1 JIT warmup drift across iterations 1–10 under WarmupCount=3.)

Verification

  • dotnet tool run fantomas --check . exits 0.
  • SymbolWrapperCaching.CurriedParameterGroups, GenericArguments, and IsAbbreviation return consistent cached wrappers (FSharp.Compiler.Service.Tests, Release net11.0): 1/1 passed.

Checklist

  • Test cases added (tests/FSharp.Compiler.Service.Tests/Symbols.fs)
  • Performance benchmarks added (tests/benchmarks/FCSBenchmarks/CompilerServiceBenchmarks/SymbolAndIwsamBenchmarks.fs)
  • Release notes entry updated (docs/release-notes/.FSharp.Compiler.Service/11.0.200.md)

@github-actions

Copy link
Copy Markdown
Contributor

✅ Release notes checked


✅ Found changes and release notes in following paths:

Warning

No PR link found in some release notes, please consider adding it.

Change path Release notes path Description
`src/Compiler` docs/release-notes/.FSharp.Compiler.Service/11.0.200.md No current pull request URL (#20985) found, please consider adding it

@T-Gro

T-Gro commented Nov 30, 2026

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
No pipelines are associated with this pull request.

@T-Gro T-Gro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖🕵️ LGTM

@github-project-automation github-project-automation Bot moved this from New to In Progress in F# Compiler and Tooling Nov 30, 2026

@T-Gro T-Gro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖🕵️

@@ -0,0 +1,189 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖🕵️ One-off benchmark is a PR artifact, not a repo artifact; remove it and the README section (keep results in the PR description).

let meths = IntrinsicMethInfosOfType cenv.infoReader None env.eAccessRights AllowMultiIntfInstantiations.Yes IgnoreOverrides m ty

if meths |> List.exists (fun meth -> not meth.IsInstance && meth.IsDispatchSlot && not meth.IsExtensionMember) then
if cenv.infoReader.HasIntrinsicStaticAbstractMethod env.eAccessRights m ty then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖🕵️ WarmCheckFileWithInterfaces 58.8 → 68.0 ms is a regression, not noise; the main scenario must not get slower.

| _ -> ValueNone

// Cached per instance, as every type predicate checks resolution first. 0 = uncomputed, 1 = resolved, 2 = unresolved.
let mutable unresolvedState = 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖🕵️ In FSI the cached unresolved state stays stale after #r loads the assembly

// B.dll: module B  type T = { X: int }
// A.dll: module A  let v : B.T = { B.X = 1 }   (compiled against B.dll; B.dll not next to A.dll)
use fsi = FsiEvaluationSession.Create(FsiEvaluationSession.GetDefaultConfiguration(), [| "fsi"; "--noninteractive" |], stdin, stdout, stderr)
fsi.EvalInteraction "#r \"a/A.dll\""
let _, check, _ = fsi.ParseAndCheckInteraction "let w = A.v"
let v = check.GetAllUsesOfAllSymbolsInFile() |> Seq.pick (fun u -> match u.Symbol with :? FSharpMemberOrFunctionOrValue as v when v.DisplayName = "v" -> Some v | _ -> None)
let ty = v.FullType
ty.IsUnresolved                // true
fsi.EvalInteraction "#r \"b/B.dll\""
ty.IsUnresolved                // PR: true (stale), main: false
ty.HasTypeDefinition           // PR: false
v.FullType.IsUnresolved        // false

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants