[Repo Assist] Perf: cache FullName, BaseType and GetInterfaces in TargetTypeDefinition#485
Draft
github-actions[bot] wants to merge 2 commits intomasterfrom
Draft
Conversation
FullName, BaseType and GetInterfaces() on TargetTypeDefinition are each computed from immutable input data (inp.Namespace/inp.Name, inp.Extends, inp.Implements) but were recomputed on every call. - FullName: allocates a new string on every call via string concatenation - BaseType: resolves the base type via txILType on every call - GetInterfaces(): resolves and allocates a new Type[] on every call For large type providers with many types (e.g. SwaggerProvider), where these properties are queried many times per type during compilation, this saves repeated allocations and type-resolution work. All three are now backed by lazy caches initialised on first access. F# lazy uses LazyThreadSafetyMode.ExecutionAndPublication by default so concurrent first-access from multiple compiler threads is safe. All 117 pre-existing tests pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
🤖 This is an automated PR from Repo Assist, an AI assistant for this repository.
Summary
TargetTypeDefinition.FullName,BaseType, andGetInterfaces()each compute their result from immutable input data (inp.Namespace/inp.Name,inp.Extends,inp.Implements) but were recomputed on every call — allocating new strings/arrays and re-running type resolution each time.For large type providers with many types (e.g. SwaggerProvider), where the F# compiler queries these properties many times per type during type-checking, this saves repeated allocations and type-resolution work.
Changes
FullNamelazy— computed once, samestringreturned thereafterBaseTypetxILType(type-resolution) every calllazy— resolved onceGetInterfaces()Array.map txILType(allocates newType[]) every calllazy— resolved and allocated onceAll three caches use F#
lazywhich defaults toLazyThreadSafetyMode.ExecutionAndPublication, so concurrent first-access from multiple F# compiler threads is safe.This is complementary to PR #471 (which cached member-wrapper arrays) and does not touch the thread-safety areas being addressed by PRs #482/#483.
Test Status
All 117 pre-existing tests pass. The
netstandard2.0build target ran OOM on the CI machine (infrastructure issue, not caused by this change — the same issue affects master); thenet8.0build and tests both pass cleanly.