[Repo Assist] perf: cache GetParameters/PropertyType/FieldType/EventHandlerType in target-model wrappers#513
Merged
dsyme merged 2 commits intoMay 1, 2026
Conversation
…target-model wrappers The tx* wrapper functions for TargetTypeDefinition member wrappers (txILConstructorDef, txILMethodDef, txILPropertyDef, txILEventDef, txILFieldDef) previously recomputed type-resolved values on every call: - GetParameters() re-ran Array.map over txILParameter on every call - PropertyType re-ran txILType on every call - GetIndexParameters() re-ran Array.map over txILParameter on every call - EventHandlerType re-ran txILType on every call - FieldType re-ran txILType on every call Since TargetTypeDefinition caches its member wrappers in lazy arrays (ctorDefs, methDefs, fieldDefs, propDefs, eventDefs), the same wrapper objects are reused across calls. Caching these derived values with lazy eliminates redundant type-resolution and array allocation on repeated access — which occurs frequently when the F# compiler type-checks a generative type provider's generated assembly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
dsyme
approved these changes
May 1, 2026
4 tasks
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.
Summary
Caches computed values in the target-model member wrappers (
txILConstructorDef,txILMethodDef,txILPropertyDef,txILEventDef,txILFieldDef) insideTargetTypeDefinitionto avoid repeated type-resolution and array allocations on every call.What was happening
Each wrapper function creates a
new XxxInfo()object expression. Before this change, several frequently-called members recomputed their results from scratch on every access:txILConstructorDefGetParameters()Array.map (txILParameter ...)every calltxILMethodDefGetParameters()Array.map (txILParameter ...)every calltxILPropertyDefPropertyTypetxILTyperesolution every calltxILPropertyDefGetIndexParameters()Array.map (txILParameter ...)every calltxILEventDefEventHandlerTypetxILTyperesolution every calltxILFieldDefFieldTypetxILTyperesolution every callWhy this matters
TargetTypeDefinitionalready caches its member wrapper arrays vialazy(ctorDefs,methDefs,fieldDefs,propDefs,eventDefs). This means the same wrapper objects are reused across calls. Without result caching inside the wrappers, every access toGetParameters(),PropertyType, etc. allocates a new array and re-runs IL type resolution — which the F# compiler does repeatedly during type inference against a generative type provider's generated assembly.Fix
Added
lazybindings before each object expression to cache the computed results:All 157 tests pass.