refactor(state): Unify window-local state and reuse the cword debounce timer#33
Merged
Conversation
Per-window match and cword state was kept in the w:pinwords window variable, incurring VimL<->Lua (de)serialization on every get/set and diverging from the module-local tables used by the cword runtime and flash. Back the window store with an in-memory table while keeping the get/set facade, add clear_win_state to release a window's entry explicitly, and drop the store on teardown.
WinClosed handling now funnels through a single cleanup_window helper that releases cword timers, flash matches and the shared window-store entry, so the in-memory window state no longer leaks once a window is gone. Replace the non-standard Partial<> annotation on setup with a concrete PinwordsRuntimeSetupOpts, and align the standalone slots default with the real config default (8 -> 9).
CursorMoved previously closed and re-created a uv timer on every move, churning handles throughout the debounce. Reuse one timer per window via stop/start and guard the callback with a per-window generation token, so a fire that was already scheduled before a restart is dropped instead of updating early or twice. Also replace the Partial<> annotation with a concrete PinwordsCwordRuntimeSetupOpts.
Benchmark Results |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
w:pinwordswindow-variable round-trips.WinClosedso the in-memory state cannot leak once a window is gone.CursorMoved.Partial<>annotations with concrete*SetupOptstypes and align the standalone runtimeslotsdefault (8 -> 9).Changes
state.clear_win_stateto release a window entry explicitly and clear the whole store on teardown.WinClosedthrough onecleanup_windowhelper that releases cword timers, flash matches and the shared window-store entry.Partial<>setup annotation with a concretePinwordsRuntimeSetupOpts.slotsdefault with the real config default (8 -> 9).CursorMoved.