Commit 2505f60
[Repo Assist] perf: cache GetParameters/PropertyType/FieldType/EventHandlerType in target-model wrappers (#513)
🤖 *This is an automated PR from Repo Assist.*
## Summary
Caches computed values in the target-model member wrappers
(`txILConstructorDef`, `txILMethodDef`, `txILPropertyDef`,
`txILEventDef`, `txILFieldDef`) inside `TargetTypeDefinition` to 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:
| Wrapper | Member | Was doing |
|---------|--------|-----------|
| `txILConstructorDef` | `GetParameters()` | `Array.map (txILParameter
...)` every call |
| `txILMethodDef` | `GetParameters()` | `Array.map (txILParameter ...)`
every call |
| `txILPropertyDef` | `PropertyType` | `txILType` resolution every call
|
| `txILPropertyDef` | `GetIndexParameters()` | `Array.map (txILParameter
...)` every call |
| `txILEventDef` | `EventHandlerType` | `txILType` resolution every call
|
| `txILFieldDef` | `FieldType` | `txILType` resolution every call |
## Why this matters
`TargetTypeDefinition` already caches its member wrapper arrays via
`lazy` (`ctorDefs`, `methDefs`, `fieldDefs`, `propDefs`, `eventDefs`).
This means the **same wrapper objects are reused** across calls. Without
result caching inside the wrappers, every access to `GetParameters()`,
`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 `lazy` bindings before each object expression to cache the
computed results:
````fsharp
// txILMethodDef (before)
override __.GetParameters() = inp.Parameters |> Array.map (txILParameter (gps, gps2))
// txILMethodDef (after)
let parametersCache = lazy (inp.Parameters |> Array.map (txILParameter (gps, gps2)))
// ...
override __.GetParameters() = parametersCache.Value
```
Same pattern applied to `txILConstructorDef`, `txILPropertyDef`,
`txILEventDef`, and `txILFieldDef`.
Note: This is independent of and complementary to PR #509 (which
optimises `Array.filter (canBindXxx)` on the bind-all path).
## Test Status
```
Passed! - Failed: 0, Passed: 157, Skipped: 0, Total: 157
````
All 157 tests pass.
> Generated by 🌈 Repo Assist, see [workflow
run](https://github.com/fsprojects/FSharp.TypeProviders.SDK/actions/runs/25196752728).
> Generated by 🌈 Repo Assist, see [workflow
run](https://github.com/fsprojects/FSharp.TypeProviders.SDK/actions/runs/25196752728).
[Learn
more](https://github.com/githubnext/agentics/blob/main/docs/repo-assist.md).
>
> To install this [agentic
workflow](https://github.com/githubnext/agentics/blob/96b9d4c39aa22359c0b38265927eadb31dcf4e2a/workflows/repo-assist.md),
run
> ```
> gh aw add
githubnext/agentics@96b9d4c
> ```
<!-- gh-aw-agentic-workflow: Repo Assist, engine: copilot, model: auto,
id: 25196752728, workflow_id: repo-assist, run:
https://github.com/fsprojects/FSharp.TypeProviders.SDK/actions/runs/25196752728
-->
<!-- gh-aw-workflow-id: repo-assist -->
---------
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>1 parent ad7621f commit 2505f60
1 file changed
Lines changed: 12 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7758 | 7758 | | |
7759 | 7759 | | |
7760 | 7760 | | |
| 7761 | + | |
7761 | 7762 | | |
7762 | 7763 | | |
7763 | 7764 | | |
7764 | 7765 | | |
7765 | 7766 | | |
7766 | 7767 | | |
7767 | 7768 | | |
7768 | | - | |
| 7769 | + | |
7769 | 7770 | | |
7770 | 7771 | | |
7771 | 7772 | | |
| |||
7792 | 7793 | | |
7793 | 7794 | | |
7794 | 7795 | | |
| 7796 | + | |
7795 | 7797 | | |
7796 | 7798 | | |
7797 | 7799 | | |
7798 | 7800 | | |
7799 | 7801 | | |
7800 | 7802 | | |
7801 | | - | |
| 7803 | + | |
7802 | 7804 | | |
7803 | 7805 | | |
7804 | 7806 | | |
| |||
7851 | 7853 | | |
7852 | 7854 | | |
7853 | 7855 | | |
| 7856 | + | |
| 7857 | + | |
7854 | 7858 | | |
7855 | 7859 | | |
7856 | 7860 | | |
7857 | 7861 | | |
7858 | 7862 | | |
7859 | 7863 | | |
7860 | 7864 | | |
7861 | | - | |
| 7865 | + | |
7862 | 7866 | | |
7863 | 7867 | | |
7864 | | - | |
| 7868 | + | |
7865 | 7869 | | |
7866 | 7870 | | |
7867 | 7871 | | |
| |||
7887 | 7891 | | |
7888 | 7892 | | |
7889 | 7893 | | |
| 7894 | + | |
7890 | 7895 | | |
7891 | 7896 | | |
7892 | 7897 | | |
7893 | 7898 | | |
7894 | 7899 | | |
7895 | 7900 | | |
7896 | 7901 | | |
7897 | | - | |
| 7902 | + | |
7898 | 7903 | | |
7899 | 7904 | | |
7900 | 7905 | | |
| |||
7918 | 7923 | | |
7919 | 7924 | | |
7920 | 7925 | | |
| 7926 | + | |
7921 | 7927 | | |
7922 | 7928 | | |
7923 | 7929 | | |
7924 | 7930 | | |
7925 | 7931 | | |
7926 | 7932 | | |
7927 | 7933 | | |
7928 | | - | |
| 7934 | + | |
7929 | 7935 | | |
7930 | 7936 | | |
7931 | 7937 | | |
| |||
0 commit comments