-
Notifications
You must be signed in to change notification settings - Fork 899
Lazy TreeChanges, move ownership of diff handle for diff results #1281
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
Conversation
Neat! My end-game would be to get rid of the three types and just let you query from a general |
@@ -52,21 +28,28 @@ protected TreeChanges() | |||
|
|||
internal TreeChanges(DiffSafeHandle diff) | |||
{ | |||
Proxy.git_diff_foreach(diff, FileCallback, null, null); | |||
this.diff = diff; | |||
this.count = new Lazy<int>(() => Proxy.git_diff_num_deltas(diff)); |
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 is not safe. What if the internal diff changes between the first access to Count and the time of enumeration?
Edit: What I mean is that count
should not be a lazy, but rather should be always pinvoked.
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.
@Therzok Oh I see. I can definitely remove the memoization here. I was (mistakenly apparently) under the impression that diffs were immutable once created. Out of curiosity, could you point me to a scenario where count would mutate?
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.
When would a diff change its size once it's been computed?
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.
Oh, I just realised that the DiffSafeHandle
is saved too. Discard my comment.
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.
A diff's size could change during rename detection, but that doesn't seem like something that's going to happen here. :)
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.
A diff's size could change during rename detection, but that doesn't seem like something that's going to happen here. :)
Yeah, and at the point where this class gets passed the diff handle rename detection (if enabled) would already have occurred so we should be safe, right?
70eb53b
to
b5e018e
Compare
Look at that green CI at last. I think this is ready for review. This is for all intents and purposes a breaking API change since we now require callers of |
74d9a63
to
87e2f56
Compare
👍 from me, can you rebase? |
This will let us perform lazy loading of details in these classes, just as we do with commits and some other classes.
Done, I don't know what's up with CI but it looks unrelated to my stuff and there's a few other PRs that's failing for the same reason so I'm suspecting master is slightly borked |
This will let us perform lazy loading of diff details in
Patch
,PatchStats
andTreeChanges
just as we do with commits and some other classes.In this initial PR I've only worked with
TreeChanges
which was where our performance concerns were. We need the fastest possible way to get the number of changed files between two trees.In order for this to be possible I had to move ownership of the diff handle to the individual diff result classes. To keep this PR as small as possible I've kept the behavior of
Patch
andPatchStats
such that while they're now disposable they eagerly load everything and dispose of the handle in their respective constructors.cc @ethomson @carlosmn