Skip to content

perf(wrap): hoist window metrics out of the per-row fine_wrap loop#521

Open
ImmanuelHaffner wants to merge 1 commit into
OXY2DEV:mainfrom
ImmanuelHaffner:perf/hoist-wrap-metrics
Open

perf(wrap): hoist window metrics out of the per-row fine_wrap loop#521
ImmanuelHaffner wants to merge 1 commit into
OXY2DEV:mainfrom
ImmanuelHaffner:perf/hoist-wrap-metrics

Conversation

@ImmanuelHaffner

Copy link
Copy Markdown
Contributor

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 #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 markdown file: getwininfo calls per render pass drop 38 → 1 with identical extmark output.

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.
OXY2DEV added a commit that referenced this pull request Jul 8, 2026
Allow users to change code block styles on the fly without forcing
arbitrary rules.

Closes #520, #521
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