Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 5 commits into from
Apr 12, 2016

Conversation

niik
Copy link
Contributor

@niik niik commented Mar 17, 2016

This will let us perform lazy loading of diff details in Patch, PatchStats and TreeChanges 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 and PatchStats such that while they're now disposable they eagerly load everything and dispose of the handle in their respective constructors.

cc @ethomson @carlosmn

@niik niik force-pushed the lazy-diff-results branch from a5230d2 to a1da99d Compare March 17, 2016 03:54
@carlosmn
Copy link
Member

Neat! My end-game would be to get rid of the three types and just let you query from a general Diff object but this is a nice improvement over what we have now.

@@ -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));
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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?

Copy link
Member

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.

Copy link
Member

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. :)

Copy link
Contributor Author

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?

@niik niik force-pushed the lazy-diff-results branch 2 times, most recently from 70eb53b to b5e018e Compare March 18, 2016 18:13
@niik niik changed the title [WIP] Lazy TreeChanges, move ownership of diff handle for diff results Lazy TreeChanges, move ownership of diff handle for diff results Mar 18, 2016
@niik
Copy link
Contributor Author

niik commented Mar 18, 2016

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 Compare<T> to dispose of the return values themselves (except not really for Patch*).

@niik niik force-pushed the lazy-diff-results branch 2 times, most recently from 74d9a63 to 87e2f56 Compare March 23, 2016 02:07
@carlosmn
Copy link
Member

👍 from me, can you rebase?

niik added 3 commits April 3, 2016 13:24
@niik niik force-pushed the lazy-diff-results branch from 87e2f56 to 5b5a7ba Compare April 3, 2016 20:39
@niik niik force-pushed the lazy-diff-results branch from 5b5a7ba to 53b267b Compare April 3, 2016 21:59
@niik
Copy link
Contributor Author

niik commented Apr 3, 2016

👍 from me, can you rebase?

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

@carlosmn carlosmn merged commit 84154d6 into master Apr 12, 2016
@carlosmn carlosmn deleted the lazy-diff-results branch April 12, 2016 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants