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
Cache Git commands related to submodules #8866
Cache Git commands related to submodules #8866
Conversation
Codecov Report
@@ Coverage Diff @@
## master #8866 +/- ##
==========================================
- Coverage 56.20% 56.18% -0.03%
==========================================
Files 921 921
Lines 65591 65593 +2
Branches 11991 11995 +4
==========================================
- Hits 36867 36853 -14
- Misses 25737 25742 +5
- Partials 2987 2998 +11
Flags with carried forward coverage won't be shown. Click here to find out more. |
var output = _gitExecutable.GetOutput(args); | ||
var output = _gitExecutable.GetOutput(args, cache: cache ? GitCommandCache : null); |
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.
How about this option?
To separate by parameters.
var output = cache switch
{
true => _gitExecutable.GetOutput(args, cache: GitCommandCache),
false => _gitExecutable.GetOutput(args)
};
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.
For this PR, I suggest to follow the current code style (i.e. not change).
But this could be changed in general.
I prefer the current ?: syntax, of course partly because I am used to that but I see no benefit with the switch here.
The current is easier to read for me and less duplicated code. Long commands where options wrap over several lines can be hard to compare.
This scales better when there are more options affecting a command too.
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.
This scales better when there are more options affecting a command too.
Could you please to show example there is you mean.
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.
For this specific option, there is no additional ?:, but other usages could have
return _gitExecutable.GetOutput(
new GitArgumentBuilder("diff")
{
"--no-color",
"-M -C",
"--name-status",
{ nullSeparated, "-z" },
_revisionDiffProvider.Get(firstRevision, secondRevision)
},
cache: noCache ? null : GitCommandCache);
This could be split, but then I prefer the following:
var args = new GitArgumentBuilder("diff")
{
"--no-color",
extraDiffArguments,
{ AppSettings.UseHistogramDiffAlgorithm, "--histogram" },
"-M -C",
diffOptions
};
var cache = cacheResult &&
!string.IsNullOrEmpty(secondRevision) &&
!string.IsNullOrEmpty(firstRevision) &&
!secondRevision.IsArtificial() &&
!firstRevision.IsArtificial()
? GitCommandCache
: null;
var patch = _gitExecutable.GetOutput(
args,
cache: cache,
outputEncoding: LosslessEncoding);
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.
In the case of the switch, the state machine is clearer.
And the appearance of "null" can signal a potential error.
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.
👍
@msftbot merge in 72 hours |
Hello @gerhardol! Because you've given me some instructions on how to help merge this pull request, I'll be modifying my merge approach. Here's how I understand your requirements for merging this pull request:
If this doesn't seem right to you, you can tell me to cancel these instructions and use the auto-merge policy that has been configured for this repository. Try telling me "forget everything I just told you". |
Will of course squash before merge, will create a PR for 3.5 too |
0178fb7
to
e0dfb54
Compare
One fixup, text summary for new submodules could be cached |
* Cache commands with sha input and no variable input like Git Notes Only fetch Git Notes for commands that are not cached * Cache GetCommitRangeDiffCount (for rev-diff) * Increase Git command cache to 50
8cafaa3
to
e9a2485
Compare
Part of #8862
Proposed changes
Cache Git commands related to submodules
Cache commands with sha input and no variable input like Git Notes
Only fetch Git Notes for commands that are not cached (Notes are not displayed in Submodule scenarios anyway).
Cache GetCommitRangeDiffCount
Used when selecting multiple commits in RevDiff
Increase Git command cache to 50
Not strictly needed, 40 is OK also for my use after this, but it seems like a reasonable change.
Screenshots
Example with one submodule changed, on a relative fast PC (Git at work is 5 times slower).
Startup followed by refresh (similar to build), marked with red line.
Commands that are cached are marked with green (so cache have effect already at first display).
Note: The refresh was done a little early, a diff command will normally be required also after the update, but for current master four more commands would be required.
Before
After
Test methodology
review and manual
✒️ I contribute this code under The Developer Certificate of Origin.