From 714b498b9a06eb71599d3d4033854977a70de891 Mon Sep 17 00:00:00 2001 From: "Alexey.Berezhnykh" Date: Fri, 28 Jun 2024 05:07:15 +0300 Subject: [PATCH 1/6] wip --- src/Compiler/AbstractIL/ilread.fs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/Compiler/AbstractIL/ilread.fs b/src/Compiler/AbstractIL/ilread.fs index 1535078bfe0..0c5ac635ebd 100644 --- a/src/Compiler/AbstractIL/ilread.fs +++ b/src/Compiler/AbstractIL/ilread.fs @@ -3249,16 +3249,22 @@ and customAttrsReader ctxtH tag : ILAttributesStored = let (ctxt: ILMetadataReader) = getHole ctxtH let mdv = ctxt.mdfile.GetView() - let reader = - { new ISeekReadIndexedRowReader, ILAttribute> with - member _.GetRow(i, row) = - seekReadCustomAttributeRow ctxt mdv i &row - - member _.GetKey(attrRow) = attrRow.parentIndex + let searchedKey = TaggedIndex(tag, idx) - member _.CompareKey(key) = hcaCompare (TaggedIndex(tag, idx)) key - - member _.ConvertRow(attrRow) = + let reader = + { new ISeekReadIndexedRowReader with + member _.GetRow(i, rowIndex) = rowIndex <- i + member _.GetKey(rowIndex) = rowIndex + + member _.CompareKey(rowIndex) = + let mutable addr = ctxt.rowAddr TableNames.CustomAttribute rowIndex + // read parentIndex + let key = seekReadHasCustomAttributeIdx ctxt mdv &addr + hcaCompare searchedKey key + + member _.ConvertRow(rowIndex) = + let mutable attrRow = Unchecked.defaultof<_> + seekReadCustomAttributeRow ctxt mdv rowIndex &attrRow seekReadCustomAttr ctxt (attrRow.typeIndex, attrRow.valueIndex) } From 00e9b163ddd2ce39866f6cd45fc374e32dc884bd Mon Sep 17 00:00:00 2001 From: "Alexey.Berezhnykh" Date: Fri, 28 Jun 2024 22:15:32 +0300 Subject: [PATCH 2/6] wip --- src/Compiler/AbstractIL/ilread.fs | 49 ++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/src/Compiler/AbstractIL/ilread.fs b/src/Compiler/AbstractIL/ilread.fs index 0c5ac635ebd..6b98fed8b52 100644 --- a/src/Compiler/AbstractIL/ilread.fs +++ b/src/Compiler/AbstractIL/ilread.fs @@ -883,7 +883,7 @@ let tomdCompare (TaggedIndex(t1: TypeOrMethodDefTag, idx1)) (TaggedIndex(t2: Typ elif idx1 > idx2 then 1 else compare t1.Tag t2.Tag -let simpleIndexCompare (idx1: int) (idx2: int) = compare idx1 idx2 +let inline simpleIndexCompare (idx1: int) (idx2: int) = compare idx1 idx2 //--------------------------------------------------------------------- // The various keys for the various caches. @@ -2305,6 +2305,7 @@ and seekReadTypeDefAsTypeUncached ctxtH (TypeDefAsTypIdx(boxity, ginst, idx)) = mkILTy boxity (ILTypeSpec.Create(seekReadTypeDefAsTypeRef ctxt idx, ginst)) and seekReadTypeDefAsTypeRef (ctxt: ILMetadataReader) idx = + let mdv = ctxt.mdfile.GetView() let enc = if seekIsTopTypeDefOfIdx ctxt idx then [] @@ -2312,11 +2313,14 @@ and seekReadTypeDefAsTypeRef (ctxt: ILMetadataReader) idx = let enclIdx = seekReadIndexedRow ( ctxt.getNumRows TableNames.Nested, - seekReadNestedRow ctxt, - fst, - simpleIndexCompare idx, + id, + id, + (fun i -> + let mutable addr = ctxt.rowAddr TableNames.Nested i + let nestedIdx = seekReadUntaggedIdx TableNames.TypeDef ctxt mdv &addr + simpleIndexCompare idx nestedIdx), isSorted ctxt TableNames.Nested, - snd + (fun i -> seekReadNestedRow ctxt i |> snd) ) let tref = seekReadTypeDefAsTypeRef ctxt enclIdx @@ -3077,11 +3081,16 @@ and seekReadMethodImpls (ctxt: ILMetadataReader) numTypars tidx = let mimpls = seekReadIndexedRows ( ctxt.getNumRows TableNames.MethodImpl, - seekReadMethodImplRow ctxt mdv, - (fun (a, _, _) -> a), - simpleIndexCompare tidx, + id, + id, + (fun i -> + let mutable addr = ctxt.rowAddr TableNames.MethodImpl i + let _tidx = seekReadUntaggedIdx TableNames.TypeDef ctxt mdv &addr + simpleIndexCompare tidx _tidx), isSorted ctxt TableNames.MethodImpl, - (fun (_, b, c) -> b, c) + (fun i -> + let _, b, c = seekReadMethodImplRow ctxt mdv i + b, c) ) mimpls @@ -3154,11 +3163,14 @@ and seekReadEvents (ctxt: ILMetadataReader) numTypars tidx = match seekReadOptionalIndexedRow ( ctxt.getNumRows TableNames.EventMap, - (fun i -> i, seekReadEventMapRow ctxt mdv i), - (fun (_, row) -> fst row), - compare tidx, + id, + id, + (fun i -> + let mutable addr = ctxt.rowAddr TableNames.EventMap i + let _tidx = seekReadUntaggedIdx TableNames.TypeDef ctxt mdv &addr + simpleIndexCompare tidx _tidx), false, - (fun (i, row) -> (i, snd row)) + (fun i -> i, seekReadEventMapRow ctxt mdv i |> snd) ) with | None -> [] @@ -3221,11 +3233,14 @@ and seekReadProperties (ctxt: ILMetadataReader) numTypars tidx = match seekReadOptionalIndexedRow ( ctxt.getNumRows TableNames.PropertyMap, - (fun i -> i, seekReadPropertyMapRow ctxt mdv i), - (fun (_, row) -> fst row), - compare tidx, + id, + id, + (fun i -> + let mutable addr = ctxt.rowAddr TableNames.PropertyMap i + let _tidx = seekReadUntaggedIdx TableNames.TypeDef ctxt mdv &addr + simpleIndexCompare tidx _tidx), false, - (fun (i, row) -> (i, snd row)) + (fun i -> i, seekReadPropertyMapRow ctxt mdv i |> snd) ) with | None -> [] From b746e560e178fbae1375126b2d7b3f9fcba94f35 Mon Sep 17 00:00:00 2001 From: "Alexey.Berezhnykh" Date: Fri, 28 Jun 2024 23:04:42 +0300 Subject: [PATCH 3/6] cleanup --- src/Compiler/AbstractIL/ilread.fs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Compiler/AbstractIL/ilread.fs b/src/Compiler/AbstractIL/ilread.fs index 6b98fed8b52..af7930229d2 100644 --- a/src/Compiler/AbstractIL/ilread.fs +++ b/src/Compiler/AbstractIL/ilread.fs @@ -3088,13 +3088,11 @@ and seekReadMethodImpls (ctxt: ILMetadataReader) numTypars tidx = let _tidx = seekReadUntaggedIdx TableNames.TypeDef ctxt mdv &addr simpleIndexCompare tidx _tidx), isSorted ctxt TableNames.MethodImpl, - (fun i -> - let _, b, c = seekReadMethodImplRow ctxt mdv i - b, c) + seekReadMethodImplRow ctxt mdv ) mimpls - |> List.map (fun (b, c) -> + |> List.map (fun (_, b, c) -> { OverrideBy = let (MethodData(enclTy, cc, nm, argTys, retTy, methInst)) = From 85dca08c9d04ce7f84145cf26ccd3a41b53bacf7 Mon Sep 17 00:00:00 2001 From: "Alexey.Berezhnykh" Date: Fri, 28 Jun 2024 23:16:32 +0300 Subject: [PATCH 4/6] formatting --- src/Compiler/AbstractIL/ilread.fs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Compiler/AbstractIL/ilread.fs b/src/Compiler/AbstractIL/ilread.fs index af7930229d2..9a6f6b8c3ab 100644 --- a/src/Compiler/AbstractIL/ilread.fs +++ b/src/Compiler/AbstractIL/ilread.fs @@ -2306,6 +2306,7 @@ and seekReadTypeDefAsTypeUncached ctxtH (TypeDefAsTypIdx(boxity, ginst, idx)) = and seekReadTypeDefAsTypeRef (ctxt: ILMetadataReader) idx = let mdv = ctxt.mdfile.GetView() + let enc = if seekIsTopTypeDefOfIdx ctxt idx then [] From 6fa1dcaf3a0a26dd8cb2a30afb6bb77c39034160 Mon Sep 17 00:00:00 2001 From: "Alexey.Berezhnykh" Date: Mon, 1 Jul 2024 23:22:20 +0300 Subject: [PATCH 5/6] release notes --- docs/release-notes/.FSharp.Compiler.Service/8.0.400.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/release-notes/.FSharp.Compiler.Service/8.0.400.md b/docs/release-notes/.FSharp.Compiler.Service/8.0.400.md index 5bda852e8f4..efb15a5fa80 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/8.0.400.md +++ b/docs/release-notes/.FSharp.Compiler.Service/8.0.400.md @@ -38,3 +38,4 @@ * Showing and inserting correct name of entities from unopened namespace/module ([Issue #14375](https://github.com/dotnet/fsharp/issues/14375), [PR #17261](https://github.com/dotnet/fsharp/pull/17261)) * Improve completion after method/property override ([PR #17292](https://github.com/dotnet/fsharp/pull/17292)) * Support lazy custom attributes calculation for `ILTypeDef` public API, improve `ExtensionAttribute` presence detecting perf. ([PR #16168](https://github.com/dotnet/fsharp/pull/16168)) +* Optimize metadata reading for type members and custom attributes. ([PR #17364](https://github.com/dotnet/fsharp/pull/17364)) From 0d4ef4f95e60b08f26c0a72751e7cf6f899e2bb3 Mon Sep 17 00:00:00 2001 From: "Alexey.Berezhnykh" Date: Wed, 10 Jul 2024 20:59:06 +0300 Subject: [PATCH 6/6] release notes --- docs/release-notes/.FSharp.Compiler.Service/8.0.400.md | 1 - docs/release-notes/.FSharp.Compiler.Service/9.0.100.md | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/release-notes/.FSharp.Compiler.Service/8.0.400.md b/docs/release-notes/.FSharp.Compiler.Service/8.0.400.md index 6edb7d49e58..60394d22e23 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/8.0.400.md +++ b/docs/release-notes/.FSharp.Compiler.Service/8.0.400.md @@ -40,4 +40,3 @@ * Showing and inserting correct name of entities from unopened namespace/module ([Issue #14375](https://github.com/dotnet/fsharp/issues/14375), [PR #17261](https://github.com/dotnet/fsharp/pull/17261)) * Improve completion after method/property override ([PR #17292](https://github.com/dotnet/fsharp/pull/17292)) * Support lazy custom attributes calculation for `ILTypeDef` public API, improve `ExtensionAttribute` presence detecting perf. ([PR #16168](https://github.com/dotnet/fsharp/pull/16168)) -* Optimize metadata reading for type members and custom attributes. ([PR #17364](https://github.com/dotnet/fsharp/pull/17364)) diff --git a/docs/release-notes/.FSharp.Compiler.Service/9.0.100.md b/docs/release-notes/.FSharp.Compiler.Service/9.0.100.md index bbe39d04166..662cd7b69ba 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/9.0.100.md +++ b/docs/release-notes/.FSharp.Compiler.Service/9.0.100.md @@ -5,5 +5,6 @@ ### Changed * 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)) * Change compiler default setting for compressedMetadata ([Issue #17379](https://github.com/dotnet/fsharp/issues/17379), [PR #17383](https://github.com/dotnet/fsharp/pull/17383)) +* Optimize metadata reading for type members and custom attributes. ([PR #17364](https://github.com/dotnet/fsharp/pull/17364)) ### Breaking Changes