Skip to content

fix(buffer): prevent active item extmark accumulation - #2005

Open
ghillb wants to merge 2 commits into
NeogitOrg:masterfrom
ghillb:fix/active-item-extmark-leak
Open

fix(buffer): prevent active item extmark accumulation#2005
ghillb wants to merge 2 commits into
NeogitOrg:masterfrom
ghillb:fix/active-item-extmark-leak

Conversation

@ghillb

@ghillb ghillb commented Aug 21, 2026

Copy link
Copy Markdown

Problem

Neovim continuously consumed approximately 100% of one logical CPU core after
a Neogit buffer remained visible while focus moved to another split.

Profiling led to the buffer's ActiveItem namespace, which had accumulated an
extremely large number of persistent extmarks. The ActiveItem provider
intentionally continues running while its source buffer is unfocused, but
Buffer:clear_namespace() previously skipped unfocused buffers. The clear was
therefore ignored while redraws continued adding new extmarks.

The provider also processed callbacks for unrelated windows because it ignored
the callback's bufnr, further increasing redraw work.

The extmark accumulation was reproduced using Neogit's buffer and decoration
APIs without Snacks. Snacks made the growing cost more visible by inspecting
extmarks, but it was not required to reproduce the underlying leak.

Solution

Allow clear_namespace() to clear its explicitly addressed buffer regardless
of focus, and restrict ActiveItem decoration updates to callbacks for their
owning buffer.

Regression tests cover repeated unfocused redraws, owner-buffer scoping, and
namespace clearing while another buffer is focused.

Testing

  • make lint
  • make test
  • git diff --check upstream/master..HEAD

@ghillb
ghillb marked this pull request as ready for review August 21, 2026 18:57
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.

1 participant