Commit 75ac611
[Repo Assist] perf/refactor: convert ILFieldDefs/ILEventDefs/ILPropertyDefs to concrete classes with lazy name-lookup caches (#502)
🤖 *This PR was created by [Repo
Assist](https://github.com/githubnext/agentics/blob/main/docs/repo-assist.md),
an automated AI assistant.*
## Summary
This PR converts `ILFieldDefs`, `ILEventDefs`, and `ILPropertyDefs` from
abstract interfaces to concrete classes, mirroring the existing
`ILMethodDefs` pattern. It adds lazy O(1) name-lookup caches throughout
and makes entries truly lazy (computed at most once per type).
### Background
Previously these three types were abstract interfaces:
```fsharp
// Before — computed on every .Entries access; linear O(n) name lookups everywhere
type ILFieldDefs =
abstract Entries: ILFieldDef[]
```
Every name-based lookup (`GetField`, `GetPropertyImpl`, `GetEvent`,
`GetEnumUnderlyingType`) called `Array.tryFind` — an O(n) linear scan.
Additionally, `seekReadEvents` and `seekReadProperties` recomputed the
entries array on every `.Entries` access (the binary reader range scan
ran again each time).
### Changes
**Concrete classes with lazy dict caches** — mirroring `ILMethodDefs`:
```fsharp
type ILFieldDefs(larr: Lazy<ILFieldDef[]>) =
let lmap = lazy (
let d = Dictionary<string, ILFieldDef>()
for f in larr.Force() do d.[f.Name] <- f
d)
member __.Entries = larr.Force()
member __.TryFindByName nm =
let scc, v = lmap.Value.TryGetValue(nm) in if scc then Some v else None
```
Similarly for `ILEventDefs` and `ILPropertyDefs`.
**Entries are now truly lazy** — `seekReadEvents`/`seekReadProperties`
previously re-ran the range scan on every `.Entries` call. Now the lazy
constructor caches after first access.
**O(1) lookups in `TypeSymbol` and `TargetTypeDefinition`**:
- `TypeSymbol.GetField/GetPropertyImpl/GetEvent` (generic
instantiations): now use `TryFindByName` instead of `Array.tryFind`
- `TargetTypeDefinition.GetField/GetPropertyImpl/GetEvent`: new lazy
`fieldDefsMap`/`propDefsMap`/`eventDefsMap` dictionaries over the
wrapped reflection objects
- `TargetTypeDefinition.GetEnumUnderlyingType`: uses `TryFindByName` for
the `"value__"` field
**All creation sites updated**: empty constants,
`seekReadFields`/`seekReadEvents`/`seekReadProperties`, and
`ProvidedTypeBuilder`.
### Trade-offs
- Slightly higher memory use per loaded `ILTypeDef` (dictionary
overhead), but only allocated on first name lookup
- No API surface changes — `Entries` still works identically;
`TryFindByName` is a new additive method
### Relation to issue #500
This PR implements the code improvements from the blocked issue #500
(which was blocked by the inclusion of `.github/dependabot.yml`). This
PR contains only the code changes, without the Dependabot config.
## Test Status
✅ **126/126 tests pass** (`dotnet test
tests/FSharp.TypeProviders.SDK.Tests.fsproj -c Release --framework
net8.0`)
Build: `dotnet build src/FSharp.TypeProviders.SDK.fsproj -c Release` —
succeeded, 0 warnings, 0 errors.
---
> Generated by 🌈 Repo Assist, see [workflow
run](https://github.com/fsprojects/FSharp.TypeProviders.SDK/actions/runs/24320373239).
[Learn
more](https://github.com/githubnext/agentics/blob/main/docs/repo-assist.md).
> Generated by 🌈 Repo Assist, see [workflow
run](https://github.com/fsprojects/FSharp.TypeProviders.SDK/actions/runs/24320373239).
[Learn
more](https://github.com/githubnext/agentics/blob/main/docs/repo-assist.md).
>
> To install this [agentic
workflow](https://github.com/githubnext/agentics/blob/97143ac59cb3a13ef2a77581f929f06719c7402a/workflows/repo-assist.md),
run
> ```
> gh aw add
githubnext/agentics@97143ac
> ```
<!-- gh-aw-agentic-workflow: Repo Assist, engine: copilot, model: auto,
id: 24320373239, workflow_id: repo-assist, run:
https://github.com/fsprojects/FSharp.TypeProviders.SDK/actions/runs/24320373239
-->
<!-- 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 c843603 commit 75ac611
1 file changed
Lines changed: 63 additions & 32 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2923 | 2923 | | |
2924 | 2924 | | |
2925 | 2925 | | |
2926 | | - | |
2927 | | - | |
| 2926 | + | |
| 2927 | + | |
| 2928 | + | |
| 2929 | + | |
| 2930 | + | |
| 2931 | + | |
| 2932 | + | |
| 2933 | + | |
| 2934 | + | |
2928 | 2935 | | |
2929 | 2936 | | |
2930 | 2937 | | |
| |||
2950 | 2957 | | |
2951 | 2958 | | |
2952 | 2959 | | |
2953 | | - | |
2954 | | - | |
| 2960 | + | |
| 2961 | + | |
| 2962 | + | |
| 2963 | + | |
| 2964 | + | |
| 2965 | + | |
| 2966 | + | |
| 2967 | + | |
| 2968 | + | |
2955 | 2969 | | |
2956 | 2970 | | |
2957 | 2971 | | |
| |||
2983 | 2997 | | |
2984 | 2998 | | |
2985 | 2999 | | |
2986 | | - | |
2987 | | - | |
| 3000 | + | |
| 3001 | + | |
| 3002 | + | |
| 3003 | + | |
| 3004 | + | |
| 3005 | + | |
| 3006 | + | |
| 3007 | + | |
| 3008 | + | |
2988 | 3009 | | |
2989 | 3010 | | |
2990 | 3011 | | |
| |||
4695 | 4716 | | |
4696 | 4717 | | |
4697 | 4718 | | |
4698 | | - | |
4699 | | - | |
| 4719 | + | |
| 4720 | + | |
4700 | 4721 | | |
4701 | 4722 | | |
4702 | 4723 | | |
4703 | 4724 | | |
4704 | 4725 | | |
4705 | | - | |
| 4726 | + | |
4706 | 4727 | | |
4707 | 4728 | | |
4708 | 4729 | | |
| |||
5774 | 5795 | | |
5775 | 5796 | | |
5776 | 5797 | | |
5777 | | - | |
5778 | | - | |
5779 | | - | |
5780 | | - | |
| 5798 | + | |
5781 | 5799 | | |
5782 | 5800 | | |
5783 | 5801 | | |
| |||
6103 | 6121 | | |
6104 | 6122 | | |
6105 | 6123 | | |
6106 | | - | |
6107 | | - | |
| 6124 | + | |
| 6125 | + | |
6108 | 6126 | | |
6109 | 6127 | | |
6110 | 6128 | | |
| |||
6114 | 6132 | | |
6115 | 6133 | | |
6116 | 6134 | | |
6117 | | - | |
6118 | 6135 | | |
6119 | | - | |
| 6136 | + | |
| 6137 | + | |
6120 | 6138 | | |
6121 | 6139 | | |
6122 | 6140 | | |
| |||
6142 | 6160 | | |
6143 | 6161 | | |
6144 | 6162 | | |
6145 | | - | |
6146 | | - | |
| 6163 | + | |
| 6164 | + | |
6147 | 6165 | | |
6148 | 6166 | | |
6149 | 6167 | | |
| |||
6154 | 6172 | | |
6155 | 6173 | | |
6156 | 6174 | | |
6157 | | - | |
| 6175 | + | |
| 6176 | + | |
6158 | 6177 | | |
6159 | 6178 | | |
6160 | 6179 | | |
| |||
7517 | 7536 | | |
7518 | 7537 | | |
7519 | 7538 | | |
7520 | | - | |
| 7539 | + | |
7521 | 7540 | | |
7522 | 7541 | | |
7523 | 7542 | | |
| |||
7531 | 7550 | | |
7532 | 7551 | | |
7533 | 7552 | | |
7534 | | - | |
7535 | | - | |
| 7553 | + | |
7536 | 7554 | | |
7537 | 7555 | | |
7538 | 7556 | | |
| |||
7546 | 7564 | | |
7547 | 7565 | | |
7548 | 7566 | | |
7549 | | - | |
7550 | | - | |
| 7567 | + | |
7551 | 7568 | | |
7552 | 7569 | | |
7553 | 7570 | | |
| |||
7997 | 8014 | | |
7998 | 8015 | | |
7999 | 8016 | | |
| 8017 | + | |
| 8018 | + | |
| 8019 | + | |
| 8020 | + | |
| 8021 | + | |
| 8022 | + | |
| 8023 | + | |
| 8024 | + | |
| 8025 | + | |
| 8026 | + | |
| 8027 | + | |
| 8028 | + | |
| 8029 | + | |
| 8030 | + | |
8000 | 8031 | | |
8001 | 8032 | | |
8002 | 8033 | | |
| |||
8066 | 8097 | | |
8067 | 8098 | | |
8068 | 8099 | | |
8069 | | - | |
| 8100 | + | |
8070 | 8101 | | |
8071 | 8102 | | |
8072 | | - | |
| 8103 | + | |
8073 | 8104 | | |
8074 | 8105 | | |
8075 | | - | |
| 8106 | + | |
8076 | 8107 | | |
8077 | 8108 | | |
8078 | 8109 | | |
| |||
8110 | 8141 | | |
8111 | 8142 | | |
8112 | 8143 | | |
8113 | | - | |
| 8144 | + | |
8114 | 8145 | | |
8115 | 8146 | | |
8116 | 8147 | | |
| |||
14114 | 14145 | | |
14115 | 14146 | | |
14116 | 14147 | | |
14117 | | - | |
14118 | | - | |
14119 | | - | |
| 14148 | + | |
| 14149 | + | |
| 14150 | + | |
14120 | 14151 | | |
14121 | 14152 | | |
14122 | 14153 | | |
| |||
0 commit comments