Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3225121

Browse files
authored
Added ILReading benchmark (dotnet#6038)
* Added benchmark for ILModuleReader
1 parent12b1d0b commit3225121

File tree

7 files changed

+95
-10
lines changed

7 files changed

+95
-10
lines changed

‎benchmarks/Benchmarks.sln‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ VisualStudioVersion = 16.0.28407.52
55
MinimumVisualStudioVersion =10.0.40219.1
66
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") ="CompilerServiceBenchmarks","CompilerServiceBenchmarks\CompilerServiceBenchmarks.fsproj","{9A3C565C-B514-4AE0-8B01-CA80E8453EB0}"
77
EndProject
8-
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") ="FSharp.Core","..\src\fsharp\FSharp.Core\FSharp.Core.fsproj","{DED3BBD7-53F4-428A-8C9F-27968E768605}"
8+
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") ="FSharp.Core","..\src\fsharp\FSharp.Core\FSharp.Core.fsproj","{DED3BBD7-53F4-428A-8C9F-27968E768605}"
99
EndProject
10-
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") ="FSharp.Compiler.Private","..\src\fsharp\FSharp.Compiler.Private\FSharp.Compiler.Private.fsproj","{2E4D67B4-522D-4CF7-97E4-BA940F0B18F3}"
10+
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") ="FSharp.Compiler.Private","..\src\fsharp\FSharp.Compiler.Private\FSharp.Compiler.Private.fsproj","{2E4D67B4-522D-4CF7-97E4-BA940F0B18F3}"
1111
EndProject
1212
Global
1313
GlobalSection(SolutionConfigurationPlatforms) =preSolution

‎benchmarks/CompilerServiceBenchmarks/Program.fs‎

Lines changed: 82 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
openSystem
22
openSystem.IO
3-
openBenchmarkDotNet.Attributes
4-
openBenchmarkDotNet.Running
3+
openSystem.Text
54
openMicrosoft.FSharp.Compiler.ErrorLogger
65
openMicrosoft.FSharp.Compiler.SourceCodeServices
76
openMicrosoft.FSharp.Compiler.Text
8-
openSystem.Text
7+
openMicrosoft.FSharp.Compiler.AbstractIL
8+
openMicrosoft.FSharp.Compiler.AbstractIL.IL
9+
openMicrosoft.FSharp.Compiler.AbstractIL.ILBinaryReader
910
openMicrosoft.CodeAnalysis.Text
11+
openBenchmarkDotNet.Attributes
12+
openBenchmarkDotNet.Running
1013

1114
moduleprivateSourceText=
1215

@@ -77,8 +80,8 @@ type SourceText with
7780
memberthis.ToFSharpSourceText()=
7881
SourceText.weakTable.GetValue(this, Runtime.CompilerServices.ConditionalWeakTable<_,_>.CreateValueCallback(SourceText.create))
7982

80-
[<ClrJob;MemoryDiagnoser>]
81-
typeCompilerServiceParsing()=
83+
[<MemoryDiagnoser>]
84+
typeCompilerService()=
8285

8386
let mutablecheckerOpt= None
8487

@@ -95,6 +98,17 @@ type CompilerServiceParsing() =
9598
IsExe=false
9699
}
97100

101+
let mutableassembliesOpt= None
102+
103+
letreaderOptions=
104+
{
105+
pdbDirPath= None
106+
ilGlobals= mkILGlobals ILScopeRef.Local
107+
reduceMemoryUsage= ReduceMemoryFlag.No
108+
metadataOnly= MetadataOnlyFlag.Yes
109+
tryGetMetadataSnapshot=fun _-> None
110+
}
111+
98112
[<GlobalSetup>]
99113
member__.Setup()=
100114
match checkerOptwith
@@ -105,8 +119,16 @@ type CompilerServiceParsing() =
105119
| None->
106120
sourceOpt<- Some<| SourceText.From(File.OpenRead("""..\..\..\..\..\src\fsharp\TypeChecker.fs"""), Encoding.Default, SourceHashAlgorithm.Sha1,true)
107121
|_->()
122+
123+
match assembliesOptwith
124+
| None->
125+
assembliesOpt<-
126+
System.AppDomain.CurrentDomain.GetAssemblies()
127+
|> Array.map(fun x->(x.Location))
128+
|> Some
129+
|_->()
108130

109-
[<IterationSetup>]
131+
[<IterationSetup(Target="Parsing")>]
110132
member__.ParsingSetup()=
111133
match checkerOptwith
112134
| None-> failwith"no checker"
@@ -124,7 +146,59 @@ type CompilerServiceParsing() =
124146
letresults= checker.ParseFile("TypeChecker.fs", source.ToFSharpSourceText(), parsingOptions)|> Async.RunSynchronously
125147
if results.ParseHadErrorsthen failwithf"parse had errors:%A" results.Errors
126148

149+
[<IterationSetup(Target="ILReading")>]
150+
member__.ILReadingSetup()=
151+
// With caching, performance increases an order of magnitude when re-reading an ILModuleReader.
152+
// Clear it for benchmarking.
153+
ClearAllILModuleReaderCache()
154+
155+
[<Benchmark>]
156+
member__.ILReading()=
157+
match assembliesOptwith
158+
| None-> failwith"no assemblies"
159+
| Some(assemblies)->
160+
// We try to read most of everything in the assembly that matter, mainly types with their properties, methods, and fields.
161+
// CustomAttrs and SecurityDecls are lazy until you call them, so we call them here for benchmarking.
162+
assemblies
163+
|> Array.iter(fun(fileName)->
164+
letreader= OpenILModuleReader fileName readerOptions
165+
166+
letilModuleDef= reader.ILModuleDef
167+
168+
letilAssemblyManifest= ilModuleDef.Manifest.Value
169+
170+
ilAssemblyManifest.CustomAttrs|> ignore
171+
ilAssemblyManifest.SecurityDecls|> ignore
172+
ilAssemblyManifest.ExportedTypes.AsList
173+
|> List.iter(fun x->
174+
x.CustomAttrs|> ignore
175+
)
176+
177+
ilModuleDef.CustomAttrs|> ignore
178+
ilModuleDef.TypeDefs.AsArray
179+
|> Array.iter(fun ilTypeDef->
180+
ilTypeDef.CustomAttrs|> ignore
181+
ilTypeDef.SecurityDecls|> ignore
182+
183+
ilTypeDef.Methods.AsArray
184+
|> Array.iter(fun ilMethodDef->
185+
ilMethodDef.CustomAttrs|> ignore
186+
ilMethodDef.SecurityDecls|> ignore
187+
)
188+
189+
ilTypeDef.Fields.AsList
190+
|> List.iter(fun ilFieldDef->
191+
ilFieldDef.CustomAttrs|> ignore
192+
)
193+
194+
ilTypeDef.Properties.AsList
195+
|> List.iter(fun ilPropertyDef->
196+
ilPropertyDef.CustomAttrs|> ignore
197+
)
198+
)
199+
)
200+
127201
[<EntryPoint>]
128202
letmain argv=
129-
let_= BenchmarkRunner.Run<CompilerServiceParsing>()
130-
0
203+
let_= BenchmarkRunner.Run<CompilerService>()
204+
0

‎benchmarks/Directory.Build.props‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Project>
2+
<ImportProject="$([MSBuild]::GetPathOfFileAbove('FSharp.Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
3+
</Project>

‎benchmarks/Directory.Build.targets‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Project>
2+
<ImportProject="$([MSBuild]::GetPathOfFileAbove('FSharp.Directory.Build.targets', '$(MSBuildThisFileDirectory)../'))" />
3+
</Project>

‎src/absil/ilread.fs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4002,6 +4002,8 @@ let OpenILModuleReaderFromBytes fileName bytes opts =
40024002
letilModule,ilAssemblyRefs,pdb= openPE(fileName, pefile, opts.pdbDirPath,(opts.reduceMemoryUsage= ReduceMemoryFlag.Yes), opts.ilGlobals,true)
40034003
new ILModuleReaderImpl(ilModule, ilAssemblyRefs,(fun()-> ClosePdbReader pdb)):> ILModuleReader
40044004

4005+
letClearAllILModuleReaderCache()= ilModuleReaderCache.Clear(ILModuleReaderCacheLockToken())
4006+
40054007
letOpenILModuleReader fileName opts=
40064008
// Pseudo-normalize the paths.
40074009
let(ILModuleReaderCacheKey(fullPath,writeStamp,_,_,_,_)as key),keyOk=

‎src/absil/ilread.fsi‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ type ILModuleReader =
8080
/// PDB files may not be read with this option.
8181
valinternalOpenILModuleReader:string->ILReaderOptions->ILModuleReader
8282

83+
valinternalClearAllILModuleReaderCache:unit->unit
84+
8385
/// Open a binary reader based on the given bytes.
8486
valinternalOpenILModuleReaderFromBytes:fileNameForDebugOutput:string->assemblyContents:byte[]->options:ILReaderOptions->ILModuleReader
8587

‎src/fsharp/FSharp.Compiler.Private/FSharp.Compiler.Private.fsproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
<InternalsVisibleToInclude="HostedCompilerServer" />
6060
<InternalsVisibleToInclude="FSharp.Tests.FSharpSuite" />
6161
<InternalsVisibleToInclude="LanguageServiceProfiling" />
62+
<InternalsVisibleToInclude="CompilerServiceBenchmarks" />
6263
</ItemGroup>
6364

6465
<ItemGroup>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp