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

Commitfd8c437

Browse files
bradenlatkin
authored andcommitted
Change pdbClose to test if files are locked before inducing GCs
closesdotnet#346The original code triggers 6 full GCs, the time is a multiple of the size of the output binary since all of the IL/metadata structures are still on the heap at this point. This takes ~600ms on my test project (of a 10s total compile).Changed to perform a check if the file is locked before inducing GC. I have been running the change and notice that occasionally one iteration of the loop is required, so the detection is working. If you remove all the code you will get a compiler error in the case that the file is locked, so this will not cause a silent regression.
1 parentdec5270 commitfd8c437

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

‎src/absil/ilsupp.fs‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ let pdbCloseDocument(documentWriter : PdbDocumentWriter) =
10481048
|> ignore
10491049

10501050
[<System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability","CA2001:AvoidCallingProblematicMethods", MessageId="System.GC.Collect")>]
1051-
letpdbClose(writer:PdbWriter)=
1051+
letpdbClose(writer:PdbWriter)dllFilename pdbFilename=
10521052
writer.symWriter.Close()
10531053
// CorSymWriter objects (ISymUnmanagedWriter) lock the files they're operating
10541054
// on (both the pdb and the binary). The locks are released only when their ref
@@ -1061,18 +1061,21 @@ let pdbClose (writer:PdbWriter) =
10611061
letrc= Marshal.ReleaseComObject(writer.symWriter)
10621062
for i=0to(rc-1)do
10631063
Marshal.ReleaseComObject(writer.symWriter)|> ignore
1064-
1065-
System.GC.Collect();
1066-
System.GC.Collect();
1067-
System.GC.WaitForPendingFinalizers();
1068-
1069-
System.GC.Collect();
1070-
System.GC.Collect();
1071-
System.GC.WaitForPendingFinalizers();
1072-
1073-
System.GC.Collect();
1074-
System.GC.Collect();
1075-
System.GC.WaitForPendingFinalizers()
1064+
1065+
letisLocked filename=
1066+
try
1067+
use x= File.Open(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.None)
1068+
false
1069+
with
1070+
|_->true
1071+
1072+
let mutableattempts=0
1073+
while(isLocked dllFilename|| isLocked pdbFilename)&& attempts<3do
1074+
// Need to induce two full collections for finalizers to run
1075+
System.GC.Collect()
1076+
System.GC.Collect()
1077+
System.GC.WaitForPendingFinalizers()
1078+
attempts<- attempts+1
10761079

10771080
letpdbSetUserEntryPoint(writer:PdbWriter)(entryMethodToken:int32)=
10781081
writer.symWriter.SetUserEntryPoint((uint32)entryMethodToken)

‎src/absil/ilsupp.fsi‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ val pdbInitialize:
9595
string(* .exe/.dll already written and closed*)->
9696
string(* .pdb to write*)->
9797
PdbWriter
98-
valpdbClose:PdbWriter->unit
98+
valpdbClose:PdbWriter->string->string->unit
9999
valpdbCloseDocument:PdbDocumentWriter->unit
100100
valpdbSetUserEntryPoint:PdbWriter->int32->unit
101101
valpdbDefineDocument:PdbWriter->string->PdbDocumentWriter

‎src/absil/ilwrite.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ let WritePdbInfo fixupOverlappingSequencePoints showTimes f fpdb info =
330330
for pdbDocin docsdo
331331
pdbCloseDocument pdbDoc
332332

333-
pdbClose!pdbw;
333+
pdbClose!pdbw f fpdb;
334334
reportTime showTimes"PDB: Closed";
335335
res
336336

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp