From 797d7f3c9e2881a44e1544b3d4ca97e8cc8a67b0 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Wed, 17 Feb 2021 14:43:12 -0800 Subject: [PATCH] index-parser: Do not use DateTime.UtcNow for controlling logging. UtcNow spends a lot of time getting a very precise system time, including leap seconds and interpolation through QueryPerformanceCounter. Use Environment.TickCount (milliseconds since boot) instead, since that just retrieves a value in shared memory that the kernel keeps up to date. This value is still suitable for controlling how much log output index parsing produces. This UtcNow call consumes 15% of the time under GitIndexParser.ParseIndex. See https://github.com/dotnet/runtime/blob/master/src/libraries/System.Private.CoreLib/src/System/DateTime.Windows.cs. --- .../Projection/GitIndexProjection.GitIndexParser.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/GVFS/GVFS.Virtualization/Projection/GitIndexProjection.GitIndexParser.cs b/GVFS/GVFS.Virtualization/Projection/GitIndexProjection.GitIndexParser.cs index 20c451cbc6..c05348e2b9 100644 --- a/GVFS/GVFS.Virtualization/Projection/GitIndexProjection.GitIndexParser.cs +++ b/GVFS/GVFS.Virtualization/Projection/GitIndexProjection.GitIndexParser.cs @@ -238,8 +238,8 @@ private FileSystemTaskResult ParseIndex( uint entryCount = this.ReadFromIndexHeader(); // Don't want to flood the logs on large indexes so only log every 500ms - const int LoggingTicksThreshold = 5000000; - long nextLogTicks = DateTime.UtcNow.Ticks + LoggingTicksThreshold; + const int LoggingTicksThreshold = 500; + int nextLogTicks = Environment.TickCount + LoggingTicksThreshold; SortedFolderEntries.InitializePools(tracer, entryCount); LazyUTF8String.InitializePools(tracer, entryCount); @@ -329,10 +329,11 @@ private FileSystemTaskResult ParseIndex( return result; } - if (DateTime.UtcNow.Ticks > nextLogTicks) + int curTicks = Environment.TickCount; + if (curTicks - nextLogTicks > 0) { tracer.RelatedInfo($"{i}/{entryCount} index entries parsed."); - nextLogTicks = DateTime.UtcNow.Ticks + LoggingTicksThreshold; + nextLogTicks = curTicks + LoggingTicksThreshold; } }