Skip to content

Commit

Permalink
Add cache for GetVisualStudioVCToolsCompilerVersion()
Browse files Browse the repository at this point in the history
Before: Was taking 99 secs over 24 threads
After: Taking 69 ms over 24 threads:

Gain: ~2.5 secs wall clock when generating projects for anvil pipeline
  • Loading branch information
jspelletier committed Nov 12, 2024
1 parent 8d2b1da commit 3f0d2da
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions Sharpmake/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,18 @@ public static Version GetVisualStudioVCToolsVersion(this DevEnv visualVersion)
return version;
}

private static ConcurrentDictionary<(DevEnv, Platform), Version> s_visualStudioCompilerVersionCache = new ConcurrentDictionary<(DevEnv, Platform), Version>();

public static Version GetVisualStudioVCToolsCompilerVersion(this DevEnv visualVersion, Platform platform)
{
string clExeFile = Path.Combine(visualVersion.GetVisualStudioBinPath(platform), "cl.exe");
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(clExeFile);
return new Version(fileVersionInfo.FileMajorPart, fileVersionInfo.FileMinorPart, fileVersionInfo.FileBuildPart, fileVersionInfo.FilePrivatePart);
var cacheKey = (visualVersion, platform);
Version version = s_visualStudioCompilerVersionCache.GetOrAdd(cacheKey, ((DevEnv, Platform) key) =>
{
string clExeFile = Path.Combine(visualVersion.GetVisualStudioBinPath(platform), "cl.exe");
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(clExeFile);
return new Version(fileVersionInfo.FileMajorPart, fileVersionInfo.FileMinorPart, fileVersionInfo.FileBuildPart, fileVersionInfo.FilePrivatePart);
});
return version;
}

/// <summary>
Expand Down

0 comments on commit 3f0d2da

Please sign in to comment.