Skip to content

fix: terrible git status performance in large repo #1519

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 1 commit into from
Dec 9, 2024
Merged

fix: terrible git status performance in large repo #1519

merged 1 commit into from
Dec 9, 2024

Conversation

33KK
Copy link
Contributor

@33KK 33KK commented Jul 11, 2024

schedule_wrap floods the event loop with work that could've been done right away much faster here. massive improvement with my goofy git repo $HOME without a .gitignore
image
image

@33KK 33KK changed the title fix: improve git status performance fix: terrible git status performance in large repo Sep 22, 2024
Copy link
Contributor

@cseickel cseickel left a comment

Choose a reason for hiding this comment

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

Schedule.wrap is usually there for a very good reason. I'm afraid I can't evaluate whether schedule.wrap is actually required or not, see: #1606

Copy link
Collaborator

@pynappo pynappo left a comment

Choose a reason for hiding this comment

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

I believe there's no need for schedule_wrap here, because the jobs are just reading git output and putting it into the lines table. The only interaction with neovim here is if should_process errors to the console, but log.error properly vim.schedules logs to the console anyways. LGTM, pinging @cseickel.

@cseickel
Copy link
Contributor

cseickel commented Dec 9, 2024

@pynappo I'll go ahead and merge this, but here are a few things to consider if bugs appear:

One reason this might have been set up this way could've been to not freeze neovim when the git work was slow. Maybe it was a bad solution to use schedule_wrap, but is there any other way to background this work?

There may have been some other reason that was not recorded in comments. Be on the lookout and I would suggest finding the PR where this code was merged for an explanation.

@cseickel cseickel merged commit ca340e0 into nvim-neo-tree:main Dec 9, 2024
@33KK
Copy link
Contributor Author

33KK commented Dec 9, 2024

schedule_wrap doesn't background the work, it more or less just postpones it, while adding overhead. It runs on a single thread either way

@33KK 33KK deleted the patch-1 branch December 9, 2024 16:01
@cseickel
Copy link
Contributor

cseickel commented Dec 9, 2024

@33KK I think it's like a javascript await, where it just task switches which at least allows the app to remain responsive even while it is handling the long running job of reading the git response in little chunks. Not really backgrounding but a similar end result from a UX point of view. If that is why it was done, doing so in batches of 100 or 1K lines would have been a better way to handle it.

Now that I am reminded, I think that is how it was originally done but someone changed it along the way.

@miversen33
Copy link
Collaborator

vim.schedule takes a callable and adds it to the uv.loop queue to be processed "later" (where later is configured by neovim on loop startup. I don't recall the configuration choices available or what is used by neovim).

I believe the default behavior is "whenever is convenient".

vim.schedule_wrap "prepares" a function for this, but importantly doesn't add it to the queue. schedule_wrap returns a callable that you call later to add the provided function to queue.

As an example, these 2 should be the same

local scheduled_function = function() vim.schedule(function() print("hello world!") end) end
-- We have created a function that when called will schedule our print statement
-- Note, nothing has happened yet, If we were to _not_ run the next line, we would never see our message
-- as it was never scheduled
scheduled_function()
-- Now we ran it, and we should see our message print to the console

And

local scheduled_function = vim.schedule_wrap(function() print("hello world!") end)
-- At this point, nothing has happened, we have simply received a function that will schedule our function later
scheduled_function()
-- Now we ran it, and we should see our message print to the console

Probably not important but figured I would explain anyway :)

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