Skip to content

fix(diagnostics): throttle sequential CocDiagnostics updates, make debouncer safe and sequential #1430

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 9 commits into from
Jul 17, 2022

Conversation

alex-courtis
Copy link
Member

@alex-courtis alex-courtis commented Jul 17, 2022

closes #1317

This took way too long...

  1. debouncer is "safe"
  2. debouncer reschedules while previous job is excuting

2 could be optional, however it suits all our current use cases including git "threads". We can add an option later if we need it.

Tested:

  • COC with the incredible number of events that [coc.nvim] Error on request (diagnosticList) #1317 produces
  • heavy, concurrent git operations e.g. rm .git/touched* builddefs/touched* docs/touched* ; for i in $(seq 1 200); do touch .git/touched$i; touch builddefs/touched$i; touch docs/touched$i; done

Did not test LSP; COC testing should be sufficient.

---@param context string identifies the callback to debounce
---@param timeout number ms to wait
---@param callback function to execute on completion
function M.debounce(context, timeout, callback)
if M.debouncers[context] then
pcall(uv.close, M.debouncers[context])
-- all execution here is done in a synchronous context; no thread safety required
Copy link
Member Author

Choose a reason for hiding this comment

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

tested exhaustively using vim.is_thread()

M.debouncers[context] = nil
local timer = uv.new_timer()
debouncer.timer = timer
timer:start(timeout, 0, function()
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the key change: perform all our control operations in the direct callback instead of during scheduled execution.

timer:stop()
end
if not timer:is_closing() then
timer:close()
Copy link
Member Author

Choose a reason for hiding this comment

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

Manual reference count handling was not necessary; libuv will clear the last reference on handle close.

@alex-courtis alex-courtis changed the title 1317 throttle diagnostics fix(diagnostics): throttle sequential CocDiagnostics updates, make debouncer thread safe Jul 17, 2022
@alex-courtis alex-courtis changed the title fix(diagnostics): throttle sequential CocDiagnostics updates, make debouncer thread safe fix(diagnostics): throttle sequential CocDiagnostics updates, make debouncer safe and sequential Jul 17, 2022
@@ -138,10 +138,6 @@ function M.load_project_status(cwd)
reload_tree_at(opts.project_root)
end)
end,
on_event0 = function()
Copy link
Member Author

Choose a reason for hiding this comment

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

I must have left this in when testing.

@alex-courtis alex-courtis requested a review from kyazdani42 July 17, 2022 03:07
@@ -888,6 +894,10 @@ Configuration for diagnostic logging.
File copy and paste actions.
Type: `boolean`, Default: `false`

*nvim-tree.log.types.dev*
Copy link
Member Author

Choose a reason for hiding this comment

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

I keep needing a "clean" log context that doesn't get removed by validate_options. Feel free to remove.

@kyazdani42 kyazdani42 merged commit 06e48c2 into master Jul 17, 2022
@kyazdani42 kyazdani42 deleted the 1317-throttle-diagnostics branch July 17, 2022 06:50
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.

[coc.nvim] Error on request (diagnosticList)
2 participants