Skip to content

Commit 82981fb

Browse files
authored
Optimize type interfaces reading from metadata (#17382)
1 parent 407658e commit 82981fb

File tree

4 files changed

+29
-55
lines changed

4 files changed

+29
-55
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,6 @@
3636
* Applied nullable reference types to FSharp.Compiler.Service itself ([PR #15310](https://github.com/dotnet/fsharp/pull/15310))
3737
* 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))
3838
* Better error reporting for unions with duplicated fields. ([PR #17521](https://github.com/dotnet/fsharp/pull/17521))
39+
* Optimize ILTypeDef interface impls reading from metadata. ([PR #17382](https://github.com/dotnet/fsharp/pull/17382))
40+
3941
### Breaking Changes

src/Compiler/AbstractIL/ilread.fs

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,16 +1425,10 @@ let seekReadParamRow (ctxt: ILMetadataReader) mdv idx =
14251425
(flags, seq, nameIdx)
14261426

14271427
/// Read Table InterfaceImpl.
1428-
let private seekReadInterfaceImplRow (ctxt: ILMetadataReader) mdv idx =
1428+
let private seekReadInterfaceIdx (ctxt: ILMetadataReader) mdv idx =
14291429
let mutable addr = ctxt.rowAddr TableNames.InterfaceImpl idx
1430-
let tidx = seekReadUntaggedIdx TableNames.TypeDef ctxt mdv &addr
1431-
let intfIdx = seekReadTypeDefOrRefOrSpecIdx ctxt mdv &addr
1432-
1433-
struct {|
1434-
TypeIdx = tidx
1435-
IntfIdx = intfIdx
1436-
IntImplIdx = idx
1437-
|}
1430+
let _tidx = seekReadUntaggedIdx TableNames.TypeDef ctxt mdv &addr
1431+
seekReadTypeDefOrRefOrSpecIdx ctxt mdv &addr
14381432

14391433
/// Read Table MemberRef.
14401434
let seekReadMemberRefRow (ctxt: ILMetadataReader) mdv idx =
@@ -1653,11 +1647,11 @@ let seekReadGenericParamRow (ctxt: ILMetadataReader) mdv idx =
16531647
(idx, seq, flags, ownerIdx, nameIdx)
16541648

16551649
// Read Table GenericParamConstraint.
1656-
let seekReadGenericParamConstraintRow (ctxt: ILMetadataReader) mdv idx =
1650+
let seekReadGenericParamConstraintIdx (ctxt: ILMetadataReader) mdv idx =
16571651
let mutable addr = ctxt.rowAddr TableNames.GenericParamConstraint idx
1658-
let pidx = seekReadUntaggedIdx TableNames.GenericParam ctxt mdv &addr
1652+
let _pidx = seekReadUntaggedIdx TableNames.GenericParam ctxt mdv &addr
16591653
let constraintIdx = seekReadTypeDefOrRefOrSpecIdx ctxt mdv &addr
1660-
(pidx, constraintIdx)
1654+
constraintIdx
16611655

16621656
/// Read Table ILMethodSpec.
16631657
let seekReadMethodSpecRow (ctxt: ILMetadataReader) mdv idx =
@@ -2248,11 +2242,16 @@ and seekReadNestedTypeDefs (ctxt: ILMetadataReader) tidx =
22482242
and seekReadInterfaceImpls (ctxt: ILMetadataReader) mdv numTypars tidx =
22492243
seekReadIndexedRows (
22502244
ctxt.getNumRows TableNames.InterfaceImpl,
2251-
seekReadInterfaceImplRow ctxt mdv,
2252-
(fun x -> x.TypeIdx),
2253-
simpleIndexCompare tidx,
2245+
id,
2246+
id,
2247+
(fun idx ->
2248+
let mutable addr = ctxt.rowAddr TableNames.InterfaceImpl idx
2249+
let _tidx = seekReadUntaggedIdx TableNames.TypeDef ctxt mdv &addr
2250+
simpleIndexCompare tidx _tidx),
22542251
isSorted ctxt TableNames.InterfaceImpl,
2255-
(fun x -> (seekReadTypeDefOrRef ctxt numTypars AsObject [] x.IntfIdx), (ctxt.customAttrsReader_InterfaceImpl, x.IntImplIdx))
2252+
(fun idx ->
2253+
let intfIdx = seekReadInterfaceIdx ctxt mdv idx
2254+
seekReadTypeDefOrRef ctxt numTypars AsObject [] intfIdx, (ctxt.customAttrsReader_InterfaceImpl, idx))
22562255
)
22572256

22582257
and seekReadGenericParams ctxt numTypars (a, b) : ILGenericParameterDefs =
@@ -2262,12 +2261,14 @@ and seekReadGenericParamsUncached ctxtH (GenericParamsIdx(numTypars, a, b)) =
22622261
let (ctxt: ILMetadataReader) = getHole ctxtH
22632262
let mdv = ctxt.mdfile.GetView()
22642263

2264+
let key = TaggedIndex(a, b)
2265+
22652266
let pars =
22662267
seekReadIndexedRows (
22672268
ctxt.getNumRows TableNames.GenericParam,
22682269
seekReadGenericParamRow ctxt mdv,
22692270
(fun (_, _, _, tomd, _) -> tomd),
2270-
tomdCompare (TaggedIndex(a, b)),
2271+
tomdCompare key,
22712272
isSorted ctxt TableNames.GenericParam,
22722273
(fun (gpidx, seq, flags, _, nameIdx) ->
22732274
let flags = int32 flags
@@ -2299,11 +2300,16 @@ and seekReadGenericParamsUncached ctxtH (GenericParamsIdx(numTypars, a, b)) =
22992300
and seekReadGenericParamConstraints (ctxt: ILMetadataReader) mdv numTypars gpidx =
23002301
seekReadIndexedRows (
23012302
ctxt.getNumRows TableNames.GenericParamConstraint,
2302-
seekReadGenericParamConstraintRow ctxt mdv,
2303-
fst,
2304-
simpleIndexCompare gpidx,
2303+
id,
2304+
id,
2305+
(fun idx ->
2306+
let mutable addr = ctxt.rowAddr TableNames.GenericParamConstraint idx
2307+
let pidx = seekReadUntaggedIdx TableNames.GenericParam ctxt mdv &addr
2308+
simpleIndexCompare gpidx pidx),
23052309
isSorted ctxt TableNames.GenericParamConstraint,
2306-
(snd >> seekReadTypeDefOrRef ctxt numTypars AsObject [])
2310+
(fun idx ->
2311+
let constraintIdx = seekReadGenericParamConstraintIdx ctxt mdv idx
2312+
seekReadTypeDefOrRef ctxt numTypars AsObject [] constraintIdx)
23072313
)
23082314

23092315
and seekReadTypeDefAsType (ctxt: ILMetadataReader) boxity (ginst: ILTypes) idx =

tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,6 @@
77
! AssemblyReference: System.Reflection.Emit.ILGeneration
88
! AssemblyReference: System.Reflection.Metadata
99
! AssemblyReference: netstandard
10-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: <IntImplIdx>j__TPar IntImplIdx
11-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: <IntImplIdx>j__TPar get_IntImplIdx()
12-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: <IntfIdx>j__TPar IntfIdx
13-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: <IntfIdx>j__TPar get_IntfIdx()
14-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: <TypeIdx>j__TPar TypeIdx
15-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: <TypeIdx>j__TPar get_TypeIdx()
16-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Boolean Equals(<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar])
17-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Boolean Equals(<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar], System.Collections.IEqualityComparer)
18-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Boolean Equals(System.Object)
19-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Boolean Equals(System.Object, System.Collections.IEqualityComparer)
20-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Int32 CompareTo(<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar])
21-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Int32 CompareTo(System.Object)
22-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Int32 CompareTo(System.Object, System.Collections.IComparer)
23-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Int32 GetHashCode()
24-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Int32 GetHashCode(System.Collections.IEqualityComparer)
25-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: System.String ToString()
26-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Void .ctor(<IntImplIdx>j__TPar, <IntfIdx>j__TPar, <TypeIdx>j__TPar)
2710
FSharp.Compiler.AbstractIL.IL+ILArgConvention+Tags: Int32 CDecl
2811
FSharp.Compiler.AbstractIL.IL+ILArgConvention+Tags: Int32 Default
2912
FSharp.Compiler.AbstractIL.IL+ILArgConvention+Tags: Int32 FastCall

tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,6 @@
77
! AssemblyReference: System.Reflection.Emit.ILGeneration
88
! AssemblyReference: System.Reflection.Metadata
99
! AssemblyReference: netstandard
10-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: <IntImplIdx>j__TPar IntImplIdx
11-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: <IntImplIdx>j__TPar get_IntImplIdx()
12-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: <IntfIdx>j__TPar IntfIdx
13-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: <IntfIdx>j__TPar get_IntfIdx()
14-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: <TypeIdx>j__TPar TypeIdx
15-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: <TypeIdx>j__TPar get_TypeIdx()
16-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Boolean Equals(<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar])
17-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Boolean Equals(<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar], System.Collections.IEqualityComparer)
18-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Boolean Equals(System.Object)
19-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Boolean Equals(System.Object, System.Collections.IEqualityComparer)
20-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Int32 CompareTo(<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar])
21-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Int32 CompareTo(System.Object)
22-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Int32 CompareTo(System.Object, System.Collections.IComparer)
23-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Int32 GetHashCode()
24-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Int32 GetHashCode(System.Collections.IEqualityComparer)
25-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: System.String ToString()
26-
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Void .ctor(<IntImplIdx>j__TPar, <IntfIdx>j__TPar, <TypeIdx>j__TPar)
2710
FSharp.Compiler.AbstractIL.IL+ILArgConvention+Tags: Int32 CDecl
2811
FSharp.Compiler.AbstractIL.IL+ILArgConvention+Tags: Int32 Default
2912
FSharp.Compiler.AbstractIL.IL+ILArgConvention+Tags: Int32 FastCall

0 commit comments

Comments
 (0)