-
-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Caching git heights #801
base: main
Are you sure you want to change the base?
Caching git heights #801
Conversation
Adds caching of git heights. As calculating the height of repositories with large volumes of commits is expensive, caching the git heights can save time in the following circumstances: - Repetitive invocations of the `GetBuildVersion` msbuild task- e.g. during `dotnet pack`'ing a project, the `GetBuildVersion` task is invoked four times - Incremental versioning- in cases where a cached height is available for older commits, this value will be used avoid the cost of recalculating the entire git height (only new commits will need to be traversed) The caching behavior is enabled by default but can be opted-out by setting the new `NerdbankGitVersioningUseHeightCache` msbuild property to `false` ## Testing ### Automated testing - Verified `GitHeightCache` can serialize + deserialize heights correctly - Verified caching has a measurable impact on performance for cases when there are many commits to traverse - All existing tests pass ### Manual testing Consumed locally-packed version of `Nerdbank.GitVersioning` in a C# project and added ~1500 commits, verifying: - Height caching takes effect on second build, dramatically decreasing build time (~10s -> ~1s) - Adding an additional single commit can leverage the cached version for the previous ~1500 commits but adds the latest - Setting the `NerdbankGitVersioningUseHeightCache` property to `false` bypasses the caching behavior.
…mmits with multiple parents (any cached height would be used and could prevent the relevant commit graph being walked)
…now cached on disk next to the `version.json`/ `version.txt` file in order that performance improvements can be seen by multiple projects.
if (versionHeightPosition.HasValue) | ||
{ | ||
int height = commit.GetHeight(repoRelativeProjectDirectory, c => CommitMatchesVersion(c, baseSemVer, versionHeightPosition.Value, tracker)); | ||
var cache = new GitHeightCache(commit.GetRepository().Info.WorkingDirectory, versionOptions.RelativeFilePath, baseVersion); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably be constructing the git height cache only when useHeightCaching
is true.
Hey @AArnott, apologies for the incredibly slow response- work was incredibly stressful for a period and the idea of finding the time to look through an MR I wrote a good year ago was just too much! So full disclosure: it's been a long time since I've thought about this MR and may not be the most reliable reviewer :) I left a comment on one minor thing I think we could improve. I think we should also provide some updates to the documentation regarding this, informing people about:
|
As first seen in #499, which was inadvertently closed prior to merging. Recreating here for review and consideration.
Summary
Adds caching of git heights. As calculating the height of repositories with large volumes of commits is expensive, caching the git heights can save time in the following circumstances:
GetBuildVersion
msbuild task- e.g. duringdotnet pack
'ing a project, theGetBuildVersion
task is invoked four timesImplementation details
When can cached results be used?
Opting out
The caching behavior is enabled by default but can be opted-out by setting the new
NerdbankGitVersioningUseHeightCache
msbuild property tofalse
Cache file
A
version.cache.json
file is created per-project with contents that look like this:Testing
Automated testing
GitHeightCache
can serialize + deserialize heights correctlyManual testing
Consumed locally-packed version of
Nerdbank.GitVersioning
in a C# project and added ~1500 commits, verifying:NerdbankGitVersioningUseHeightCache
property tofalse
bypasses the caching behavior.