Skip to content

Commit aa2a9e1

Browse files
DedSec256psfinakivzarytovskii
authored
Optimize metadata members and custom attributes reading (#17364)
* wip * wip * cleanup * formatting * release notes * release notes --------- Co-authored-by: Petr <[email protected]> Co-authored-by: Vlad Zarytovskii <[email protected]>
1 parent 3dbbcc7 commit aa2a9e1

File tree

2 files changed

+48
-27
lines changed

2 files changed

+48
-27
lines changed

docs/release-notes/.FSharp.Compiler.Service/9.0.100.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
* Change compiler default setting realsig+ when building assemblies ([Issue #17384](https://github.com/dotnet/fsharp/issues/17384), [PR #17378](https://github.com/dotnet/fsharp/pull/17385))
1414
* Change compiler default setting for compressedMetadata ([Issue #17379](https://github.com/dotnet/fsharp/issues/17379), [PR #17383](https://github.com/dotnet/fsharp/pull/17383))
15+
* Optimize metadata reading for type members and custom attributes. ([PR #17364](https://github.com/dotnet/fsharp/pull/17364))
1516
* Enforce `AttributeTargets` on unions. ([PR #17389](https://github.com/dotnet/fsharp/pull/17389))
1617

1718
### Breaking Changes

src/Compiler/AbstractIL/ilread.fs

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ let tomdCompare (TaggedIndex(t1: TypeOrMethodDefTag, idx1)) (TaggedIndex(t2: Typ
883883
elif idx1 > idx2 then 1
884884
else compare t1.Tag t2.Tag
885885

886-
let simpleIndexCompare (idx1: int) (idx2: int) = compare idx1 idx2
886+
let inline simpleIndexCompare (idx1: int) (idx2: int) = compare idx1 idx2
887887

888888
//---------------------------------------------------------------------
889889
// The various keys for the various caches.
@@ -2314,18 +2314,23 @@ and seekReadTypeDefAsTypeUncached ctxtH (TypeDefAsTypIdx(boxity, ginst, idx)) =
23142314
mkILTy boxity (ILTypeSpec.Create(seekReadTypeDefAsTypeRef ctxt idx, ginst))
23152315

23162316
and seekReadTypeDefAsTypeRef (ctxt: ILMetadataReader) idx =
2317+
let mdv = ctxt.mdfile.GetView()
2318+
23172319
let enc =
23182320
if seekIsTopTypeDefOfIdx ctxt idx then
23192321
[]
23202322
else
23212323
let enclIdx =
23222324
seekReadIndexedRow (
23232325
ctxt.getNumRows TableNames.Nested,
2324-
seekReadNestedRow ctxt,
2325-
fst,
2326-
simpleIndexCompare idx,
2326+
id,
2327+
id,
2328+
(fun i ->
2329+
let mutable addr = ctxt.rowAddr TableNames.Nested i
2330+
let nestedIdx = seekReadUntaggedIdx TableNames.TypeDef ctxt mdv &addr
2331+
simpleIndexCompare idx nestedIdx),
23272332
isSorted ctxt TableNames.Nested,
2328-
snd
2333+
(fun i -> seekReadNestedRow ctxt i |> snd)
23292334
)
23302335

23312336
let tref = seekReadTypeDefAsTypeRef ctxt enclIdx
@@ -3086,15 +3091,18 @@ and seekReadMethodImpls (ctxt: ILMetadataReader) numTypars tidx =
30863091
let mimpls =
30873092
seekReadIndexedRows (
30883093
ctxt.getNumRows TableNames.MethodImpl,
3089-
seekReadMethodImplRow ctxt mdv,
3090-
(fun (a, _, _) -> a),
3091-
simpleIndexCompare tidx,
3094+
id,
3095+
id,
3096+
(fun i ->
3097+
let mutable addr = ctxt.rowAddr TableNames.MethodImpl i
3098+
let _tidx = seekReadUntaggedIdx TableNames.TypeDef ctxt mdv &addr
3099+
simpleIndexCompare tidx _tidx),
30923100
isSorted ctxt TableNames.MethodImpl,
3093-
(fun (_, b, c) -> b, c)
3101+
seekReadMethodImplRow ctxt mdv
30943102
)
30953103

30963104
mimpls
3097-
|> List.map (fun (b, c) ->
3105+
|> List.map (fun (_, b, c) ->
30983106
{
30993107
OverrideBy =
31003108
let (MethodData(enclTy, cc, nm, argTys, retTy, methInst)) =
@@ -3163,11 +3171,14 @@ and seekReadEvents (ctxt: ILMetadataReader) numTypars tidx =
31633171
match
31643172
seekReadOptionalIndexedRow (
31653173
ctxt.getNumRows TableNames.EventMap,
3166-
(fun i -> i, seekReadEventMapRow ctxt mdv i),
3167-
(fun (_, row) -> fst row),
3168-
compare tidx,
3174+
id,
3175+
id,
3176+
(fun i ->
3177+
let mutable addr = ctxt.rowAddr TableNames.EventMap i
3178+
let _tidx = seekReadUntaggedIdx TableNames.TypeDef ctxt mdv &addr
3179+
simpleIndexCompare tidx _tidx),
31693180
false,
3170-
(fun (i, row) -> (i, snd row))
3181+
(fun i -> i, seekReadEventMapRow ctxt mdv i |> snd)
31713182
)
31723183
with
31733184
| None -> []
@@ -3230,11 +3241,14 @@ and seekReadProperties (ctxt: ILMetadataReader) numTypars tidx =
32303241
match
32313242
seekReadOptionalIndexedRow (
32323243
ctxt.getNumRows TableNames.PropertyMap,
3233-
(fun i -> i, seekReadPropertyMapRow ctxt mdv i),
3234-
(fun (_, row) -> fst row),
3235-
compare tidx,
3244+
id,
3245+
id,
3246+
(fun i ->
3247+
let mutable addr = ctxt.rowAddr TableNames.PropertyMap i
3248+
let _tidx = seekReadUntaggedIdx TableNames.TypeDef ctxt mdv &addr
3249+
simpleIndexCompare tidx _tidx),
32363250
false,
3237-
(fun (i, row) -> (i, snd row))
3251+
(fun i -> i, seekReadPropertyMapRow ctxt mdv i |> snd)
32383252
)
32393253
with
32403254
| None -> []
@@ -3258,16 +3272,22 @@ and customAttrsReader ctxtH tag : ILAttributesStored =
32583272
let (ctxt: ILMetadataReader) = getHole ctxtH
32593273
let mdv = ctxt.mdfile.GetView()
32603274

3261-
let reader =
3262-
{ new ISeekReadIndexedRowReader<CustomAttributeRow, TaggedIndex<HasCustomAttributeTag>, ILAttribute> with
3263-
member _.GetRow(i, row) =
3264-
seekReadCustomAttributeRow ctxt mdv i &row
3265-
3266-
member _.GetKey(attrRow) = attrRow.parentIndex
3267-
3268-
member _.CompareKey(key) = hcaCompare (TaggedIndex(tag, idx)) key
3275+
let searchedKey = TaggedIndex(tag, idx)
32693276

3270-
member _.ConvertRow(attrRow) =
3277+
let reader =
3278+
{ new ISeekReadIndexedRowReader<int, int, ILAttribute> with
3279+
member _.GetRow(i, rowIndex) = rowIndex <- i
3280+
member _.GetKey(rowIndex) = rowIndex
3281+
3282+
member _.CompareKey(rowIndex) =
3283+
let mutable addr = ctxt.rowAddr TableNames.CustomAttribute rowIndex
3284+
// read parentIndex
3285+
let key = seekReadHasCustomAttributeIdx ctxt mdv &addr
3286+
hcaCompare searchedKey key
3287+
3288+
member _.ConvertRow(rowIndex) =
3289+
let mutable attrRow = Unchecked.defaultof<_>
3290+
seekReadCustomAttributeRow ctxt mdv rowIndex &attrRow
32713291
seekReadCustomAttr ctxt (attrRow.typeIndex, attrRow.valueIndex)
32723292
}
32733293

0 commit comments

Comments
 (0)