From 82981fbeb280d6aaeff1542c4093bf2449ac9e2a Mon Sep 17 00:00:00 2001 From: Alex Berezhnykh Date: Thu, 29 Aug 2024 11:11:23 +0300 Subject: [PATCH] Optimize type interfaces reading from metadata (#17382) --- .../.FSharp.Compiler.Service/9.0.100.md | 2 + src/Compiler/AbstractIL/ilread.fs | 48 +++++++++++-------- ...ervice.SurfaceArea.netstandard20.debug.bsl | 17 ------- ...vice.SurfaceArea.netstandard20.release.bsl | 17 ------- 4 files changed, 29 insertions(+), 55 deletions(-) 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 12adae55598..b23aae2e37a 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/9.0.100.md +++ b/docs/release-notes/.FSharp.Compiler.Service/9.0.100.md @@ -36,4 +36,6 @@ * Applied nullable reference types to FSharp.Compiler.Service itself ([PR #15310](https://github.com/dotnet/fsharp/pull/15310)) * Ensure that isinteractive multi-emit backing fields are not public. ([Issue #17439](https://github.com/dotnet/fsharp/issues/17438)), ([PR #17439](https://github.com/dotnet/fsharp/pull/17439)) * Better error reporting for unions with duplicated fields. ([PR #17521](https://github.com/dotnet/fsharp/pull/17521)) +* Optimize ILTypeDef interface impls reading from metadata. ([PR #17382](https://github.com/dotnet/fsharp/pull/17382)) + ### Breaking Changes diff --git a/src/Compiler/AbstractIL/ilread.fs b/src/Compiler/AbstractIL/ilread.fs index 5dcc051ab9f..0ff6896f82d 100644 --- a/src/Compiler/AbstractIL/ilread.fs +++ b/src/Compiler/AbstractIL/ilread.fs @@ -1425,16 +1425,10 @@ let seekReadParamRow (ctxt: ILMetadataReader) mdv idx = (flags, seq, nameIdx) /// Read Table InterfaceImpl. -let private seekReadInterfaceImplRow (ctxt: ILMetadataReader) mdv idx = +let private seekReadInterfaceIdx (ctxt: ILMetadataReader) mdv idx = let mutable addr = ctxt.rowAddr TableNames.InterfaceImpl idx - let tidx = seekReadUntaggedIdx TableNames.TypeDef ctxt mdv &addr - let intfIdx = seekReadTypeDefOrRefOrSpecIdx ctxt mdv &addr - - struct {| - TypeIdx = tidx - IntfIdx = intfIdx - IntImplIdx = idx - |} + let _tidx = seekReadUntaggedIdx TableNames.TypeDef ctxt mdv &addr + seekReadTypeDefOrRefOrSpecIdx ctxt mdv &addr /// Read Table MemberRef. let seekReadMemberRefRow (ctxt: ILMetadataReader) mdv idx = @@ -1653,11 +1647,11 @@ let seekReadGenericParamRow (ctxt: ILMetadataReader) mdv idx = (idx, seq, flags, ownerIdx, nameIdx) // Read Table GenericParamConstraint. -let seekReadGenericParamConstraintRow (ctxt: ILMetadataReader) mdv idx = +let seekReadGenericParamConstraintIdx (ctxt: ILMetadataReader) mdv idx = let mutable addr = ctxt.rowAddr TableNames.GenericParamConstraint idx - let pidx = seekReadUntaggedIdx TableNames.GenericParam ctxt mdv &addr + let _pidx = seekReadUntaggedIdx TableNames.GenericParam ctxt mdv &addr let constraintIdx = seekReadTypeDefOrRefOrSpecIdx ctxt mdv &addr - (pidx, constraintIdx) + constraintIdx /// Read Table ILMethodSpec. let seekReadMethodSpecRow (ctxt: ILMetadataReader) mdv idx = @@ -2248,11 +2242,16 @@ and seekReadNestedTypeDefs (ctxt: ILMetadataReader) tidx = and seekReadInterfaceImpls (ctxt: ILMetadataReader) mdv numTypars tidx = seekReadIndexedRows ( ctxt.getNumRows TableNames.InterfaceImpl, - seekReadInterfaceImplRow ctxt mdv, - (fun x -> x.TypeIdx), - simpleIndexCompare tidx, + id, + id, + (fun idx -> + let mutable addr = ctxt.rowAddr TableNames.InterfaceImpl idx + let _tidx = seekReadUntaggedIdx TableNames.TypeDef ctxt mdv &addr + simpleIndexCompare tidx _tidx), isSorted ctxt TableNames.InterfaceImpl, - (fun x -> (seekReadTypeDefOrRef ctxt numTypars AsObject [] x.IntfIdx), (ctxt.customAttrsReader_InterfaceImpl, x.IntImplIdx)) + (fun idx -> + let intfIdx = seekReadInterfaceIdx ctxt mdv idx + seekReadTypeDefOrRef ctxt numTypars AsObject [] intfIdx, (ctxt.customAttrsReader_InterfaceImpl, idx)) ) and seekReadGenericParams ctxt numTypars (a, b) : ILGenericParameterDefs = @@ -2262,12 +2261,14 @@ and seekReadGenericParamsUncached ctxtH (GenericParamsIdx(numTypars, a, b)) = let (ctxt: ILMetadataReader) = getHole ctxtH let mdv = ctxt.mdfile.GetView() + let key = TaggedIndex(a, b) + let pars = seekReadIndexedRows ( ctxt.getNumRows TableNames.GenericParam, seekReadGenericParamRow ctxt mdv, (fun (_, _, _, tomd, _) -> tomd), - tomdCompare (TaggedIndex(a, b)), + tomdCompare key, isSorted ctxt TableNames.GenericParam, (fun (gpidx, seq, flags, _, nameIdx) -> let flags = int32 flags @@ -2299,11 +2300,16 @@ and seekReadGenericParamsUncached ctxtH (GenericParamsIdx(numTypars, a, b)) = and seekReadGenericParamConstraints (ctxt: ILMetadataReader) mdv numTypars gpidx = seekReadIndexedRows ( ctxt.getNumRows TableNames.GenericParamConstraint, - seekReadGenericParamConstraintRow ctxt mdv, - fst, - simpleIndexCompare gpidx, + id, + id, + (fun idx -> + let mutable addr = ctxt.rowAddr TableNames.GenericParamConstraint idx + let pidx = seekReadUntaggedIdx TableNames.GenericParam ctxt mdv &addr + simpleIndexCompare gpidx pidx), isSorted ctxt TableNames.GenericParamConstraint, - (snd >> seekReadTypeDefOrRef ctxt numTypars AsObject []) + (fun idx -> + let constraintIdx = seekReadGenericParamConstraintIdx ctxt mdv idx + seekReadTypeDefOrRef ctxt numTypars AsObject [] constraintIdx) ) and seekReadTypeDefAsType (ctxt: ILMetadataReader) boxity (ginst: ILTypes) idx = diff --git a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl index 820f94aa28a..77a6ce3e699 100644 --- a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl +++ b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl @@ -7,23 +7,6 @@ ! AssemblyReference: System.Reflection.Emit.ILGeneration ! AssemblyReference: System.Reflection.Metadata ! AssemblyReference: netstandard -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: j__TPar IntImplIdx -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: j__TPar get_IntImplIdx() -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: j__TPar IntfIdx -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: j__TPar get_IntfIdx() -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: j__TPar TypeIdx -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: j__TPar get_TypeIdx() -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: Boolean Equals(<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]) -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: Boolean Equals(<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar], System.Collections.IEqualityComparer) -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: Boolean Equals(System.Object) -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: Boolean Equals(System.Object, System.Collections.IEqualityComparer) -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: Int32 CompareTo(<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]) -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: Int32 CompareTo(System.Object) -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: Int32 CompareTo(System.Object, System.Collections.IComparer) -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: Int32 GetHashCode() -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: Int32 GetHashCode(System.Collections.IEqualityComparer) -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: System.String ToString() -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: Void .ctor(j__TPar, j__TPar, j__TPar) FSharp.Compiler.AbstractIL.IL+ILArgConvention+Tags: Int32 CDecl FSharp.Compiler.AbstractIL.IL+ILArgConvention+Tags: Int32 Default FSharp.Compiler.AbstractIL.IL+ILArgConvention+Tags: Int32 FastCall diff --git a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl index 820f94aa28a..77a6ce3e699 100644 --- a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl +++ b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl @@ -7,23 +7,6 @@ ! AssemblyReference: System.Reflection.Emit.ILGeneration ! AssemblyReference: System.Reflection.Metadata ! AssemblyReference: netstandard -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: j__TPar IntImplIdx -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: j__TPar get_IntImplIdx() -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: j__TPar IntfIdx -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: j__TPar get_IntfIdx() -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: j__TPar TypeIdx -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: j__TPar get_TypeIdx() -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: Boolean Equals(<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]) -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: Boolean Equals(<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar], System.Collections.IEqualityComparer) -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: Boolean Equals(System.Object) -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: Boolean Equals(System.Object, System.Collections.IEqualityComparer) -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: Int32 CompareTo(<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]) -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: Int32 CompareTo(System.Object) -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: Int32 CompareTo(System.Object, System.Collections.IComparer) -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: Int32 GetHashCode() -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: Int32 GetHashCode(System.Collections.IEqualityComparer) -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: System.String ToString() -<>f__AnonymousType10003411232265`3[j__TPar,j__TPar,j__TPar]: Void .ctor(j__TPar, j__TPar, j__TPar) FSharp.Compiler.AbstractIL.IL+ILArgConvention+Tags: Int32 CDecl FSharp.Compiler.AbstractIL.IL+ILArgConvention+Tags: Int32 Default FSharp.Compiler.AbstractIL.IL+ILArgConvention+Tags: Int32 FastCall