Skip to content

Discard changes performance improvements - #1899

Merged
joshaber merged 42 commits into
masterfrom
discard-changes-loading-state
Aug 8, 2017
Merged

joshaber merged 42 commits into
masterfrom
discard-changes-loading-state

Conversation

@niik

@niik niik commented Jun 5, 2017

Copy link
Copy Markdown
Member

This changes our discard changes logic from our current approach of resetting the entire index and calling git checkout with a potentially too long (see #1668) argument list of files to instead carefully partially resetting the index and then using checkout-index with a set of files passed on stdin.

New discard logic

We're trying to not invoke git linearly with the number of files to discard
so we're doing our discards in three conceptual steps.

  1. Figure out what the index thinks has changed as compared to the previous commit. For users who exclusive interact with Git using Desktop this will almost always empty which, as it turns out, is great for us.
  2. Figure out if any of the files that we've been asked to discard are changed in the index and if so, reset them such that the index is set up just as the previous commit for the paths we're discarding.
  3. Checkout all the files that we've discarded that existed in the previous commit from the index.

moveItemToTrash

Electron's moveItemToTrash function which we're using is synchronous and seems to take 20+ ms per file to run on my machine (Windows). Since we were calling this in a loop without yielding to the browser for all the files that needed to be discarded we were effectively locking the app, making it unresponsive until all those operations where executed. In a scenario like the one described in #1889 that could end up locking the app completely for a over a minute, or more.

To combat this I've implemented a work queue that schedules synchronous work with a high priority across as many animation frames as needed. While an ideal solution would be an asynchronous version of moveItemToTrash and a version of it that accepts an array of files to move to trash this will at least solve the immediate problem.

Fixes #1889, #1668

niik added 27 commits June 5, 2017 10:09
Turns out idle callbacks behave funnily, in my testing they didn't fire unless there was user interaction (which seemed most counter-intuitive). I had to move my pointer over the window for it to fire at all.
@joshaber joshaber assigned joshaber and unassigned joshaber Jun 5, 2017
@j-f1

j-f1 commented Jun 9, 2017

Copy link
Copy Markdown
Contributor

@niik You should open an issue on electron/electron to get an async version of moveItemToTrash.

@niik

niik commented Jul 28, 2017

Copy link
Copy Markdown
Member Author

I'm gonna mark this as ready for review now just before heading out to vacation which is a bit of an unfair move and I apologize. If changes are needed on this feel free to either make them yourselves or leave this until I get back.

One note for this is that I've removed the functionality to remove a previously tracked file from the index when ignoring it. There's a couple of reasons for that which I've discussed with @joshaber. One is that the way we've got this set up right now is if you discard any file named '.gitignore' we will reset the entire index which blows away any conflict metadata. It also differs from how Git itself deals with ignored files and diverging from Git is something we've learned from experience can cause a great deal of pain down the line. When talking this through with @joshaber we settled on the easy approach of not doing anything magical when ignoring files and seeing how that plays out.

@niik niik added the ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Jul 28, 2017
@joshaber joshaber self-assigned this Aug 8, 2017

@joshaber joshaber left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a few changes but nothing substantive. Looks good 👍

@joshaber
joshaber merged commit a969141 into master Aug 8, 2017
@joshaber
joshaber deleted the discard-changes-loading-state branch August 8, 2017 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-review Pull Requests that are ready to be reviewed by the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants