perf(wrap): hoist window metrics out of the per-row fine_wrap loop#521
Open
ImmanuelHaffner wants to merge 1 commit into
Open
perf(wrap): hoist window metrics out of the per-row fine_wrap loop#521ImmanuelHaffner wants to merge 1 commit into
ImmanuelHaffner wants to merge 1 commit into
Conversation
wrap.render() called fine_wrap() once per wrapped row, and each call ran vim.fn.getwininfo(win) plus vim.wo[win] reads to derive textoff/width. Those values are window-invariant across a single render pass, so this allocated a fresh getwininfo dict for every wrapped line (N calls, N allocations, extra GC pressure), on a path that fires on every scroll, edit and streamed chat token. Extract the metric resolution (including the OXY2DEV#434 signcolumn fixup) into wrap.win_width(win), compute it once in wrap.render(), and pass the width into fine_wrap(). The whole row loop now runs inside a single nvim_win_call instead of one per row. Measured on an example stress test markdown file: getwininfo calls per render pass drop 38 -> 1 with identical extmark output.
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.
wrap.render()calledfine_wrap()once per wrapped row, and each call ranvim.fn.getwininfo(win)plusvim.wo[win]reads to derivetextoff/width. Those values are window-invariant across a single render pass, so this allocated a freshgetwininfodict for every wrapped line (N calls, N allocations, extra GC pressure), on a path that fires on every scroll, edit and streamed chat token.Extract the metric resolution (including the #434 signcolumn fixup) into
wrap.win_width(win), compute it once inwrap.render(), and pass the width intofine_wrap(). The whole row loop now runs inside a singlenvim_win_callinstead of one per row.Measured on an example markdown file:
getwininfocalls per render pass drop 38 → 1 with identical extmark output.