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

Commit18b7575

Browse files
authored
Avoiding loading and processing same cert file to improve cold start performance
If two files `stat` to the same pair of identifiers, they don't both need to be loaded.
1 parent0d1c8cb commit18b7575

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

‎src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/OpenSslCachedSystemStoreProvider.cs‎

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private static bool LastWriteTimesHaveChanged()
114114

115115
if(s_rootStoreFile!=null)
116116
{
117-
_=TryStatFile(s_rootStoreFile,outDateTimelastModified);
117+
_=TryStatFile(s_rootStoreFile,outDateTimelastModified,out_);
118118
if(lastModified!=s_fileLastWrite)
119119
{
120120
returntrue;
@@ -149,6 +149,7 @@ private static Tuple<SafeX509StackHandle, SafeX509StackHandle> LoadMachineStores
149149

150150
varuniqueRootCerts=newHashSet<X509Certificate2>();
151151
varuniqueIntermediateCerts=newHashSet<X509Certificate2>();
152+
varprocessedFiles=newHashSet<(longIno,longDev)>();
152153
boolfirstLoad=(s_nativeCollections==null);
153154

154155
if(firstLoad)
@@ -197,23 +198,23 @@ bool ProcessDir(string dir, out DateTime lastModified)
197198

198199
foreach(stringfileinDirectory.EnumerateFiles(dir))
199200
{
200-
hasStoreData|=ProcessFile(file,out_,skipStat:true);
201+
hasStoreData|=ProcessFile(file,out_);
201202
}
202203

203204
returnhasStoreData;
204205
}
205206

206-
boolProcessFile(stringfile,outDateTimelastModified,boolskipStat=false)
207+
boolProcessFile(stringfile,outDateTimelastModified)
207208
{
208209
boolreadData=false;
209-
210-
if(skipStat)
210+
if(!TryStatFile(file,outlastModified,out(long,long)fileId))
211211
{
212-
lastModified=default;
212+
returnfalse;
213213
}
214-
elseif(!TryStatFile(file,outlastModified))
214+
215+
if(processedFiles.Contains(fileId))
215216
{
216-
returnfalse;
217+
returntrue;
217218
}
218219

219220
using(SafeBioHandlefileBio=Interop.Crypto.BioNewFile(file,"rb"))
@@ -281,6 +282,11 @@ bool ProcessFile(string file, out DateTime lastModified, bool skipStat = false)
281282
}
282283
}
283284

285+
if(readData)
286+
{
287+
processedFiles.Add(fileId);
288+
}
289+
284290
returnreadData;
285291
}
286292

@@ -307,7 +313,6 @@ bool ProcessFile(string file, out DateTime lastModified, bool skipStat = false)
307313
// In order to maintain "finalization-free" the GetNativeCollections method would need to
308314
// DangerousAddRef, and the callers would need to DangerousRelease, adding more interlocked operations
309315
// on every call.
310-
311316
Volatile.Write(refs_nativeCollections,newCollections);
312317
s_recheckStopwatch.Restart();
313318
returnnewCollections;
@@ -361,24 +366,24 @@ private static string[] GetRootStoreDirectories(out bool isDefault)
361366
returndirectories;
362367
}
363368

364-
privatestaticboolTryStatFile(stringpath,outDateTimelastModified)
365-
=>TryStat(path,Interop.Sys.FileTypes.S_IFREG,outlastModified);
366-
367369
privatestaticboolTryStatDirectory(stringpath,outDateTimelastModified)
368-
=>TryStat(path,Interop.Sys.FileTypes.S_IFDIR,outlastModified);
370+
=>TryStat(path,Interop.Sys.FileTypes.S_IFDIR,outlastModified,out_);
369371

370-
privatestaticboolTryStat(stringpath,intfileType,outDateTimelastModified)
372+
privatestaticboolTryStatFile(stringpath,outDateTimelastModified,out(long,long)fileId)
373+
=>TryStat(path,Interop.Sys.FileTypes.S_IFREG,outlastModified,outfileId);
374+
375+
privatestaticboolTryStat(stringpath,intfileType,outDateTimelastModified,out(long,long)fileId)
371376
{
372377
lastModified=default;
373-
374-
Interop.Sys.FileStatusstatus;
378+
fileId=default;
375379
// Use Stat to follow links.
376-
if(Interop.Sys.Stat(path,outstatus)<0||
380+
if(Interop.Sys.Stat(path,outInterop.Sys.FileStatusstatus)<0||
377381
(status.Mode&Interop.Sys.FileTypes.S_IFMT)!=fileType)
378382
{
379383
returnfalse;
380384
}
381385

386+
fileId=(status.Ino,status.Dev);
382387
lastModified=DateTime.UnixEpoch+TimeSpan.FromTicks(status.MTime*TimeSpan.TicksPerSecond+status.MTimeNsec/TimeSpan.NanosecondsPerTick);
383388
returntrue;
384389
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp