index-parser: get the time in a cheaper way by neerajsi-msft · Pull Request #1798 · microsoft/VFSForGit (original) (raw)

DateTime.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 the UtcNow implementation at:
See https://github.com/dotnet/runtime/blob/master/src/libraries/System.Private.CoreLib/src/System/DateTime.Windows.cs.