Skip to content

Reuse grapheme offsets to speed up word motions - #5

Merged
fcoury merged 2 commits into
mainfrom
perf/reuse-word-grapheme-offsets
Nov 26, 2026
Merged

fcoury merged 2 commits into
mainfrom
perf/reuse-word-grapheme-offsets

Conversation

@fcoury

@fcoury fcoury commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Word scans recompute the same grapheme boundary two or three times when advancing through a word. Reuse that offset in backward scans and forward word-end scans to reduce work for b, e, and the related motions and operators that share this implementation.

The first commit adds a standalone benchmark for w, b, e, iw, and aw at counts 1, 10, and 100, using both string and Ropey text sources. It samples valid grapheme boundaries and provides exact-output verification. The second commit applies the optimization.

Measured on macOS arm64 with Rust 1.99.1 release builds. Each cell below is a geometric mean across fixtures of the median of three paired baseline/candidate runtime ratios. Higher is faster.

Fixtures Adapter Motion Count 1 Count 10 Count 100
Source, multilingual, long line str b 1.193× 1.232× 1.214×
Source, multilingual, long line str e 1.720× 1.635× 1.632×
Source, multilingual, long line Ropey b 1.159× 1.173× 1.169×
Source, multilingual, long line Ropey e 1.512× 1.442× 1.438×
CRLF and Unicode holdout str b 1.184× 1.174× 1.154×
CRLF and Unicode holdout str e 1.527× 1.475× 1.473×
CRLF and Unicode holdout Ropey b 1.116× 1.129× 1.123×
CRLF and Unicode holdout Ropey e 1.403× 1.350× 1.358×

How to test

Compare the first commit (benchmark baseline) with the second commit using the same toolchain and machine.

cargo bench --locked --features ropey --bench word_motions
cargo bench --locked --features ropey --bench word_motions -- --holdout
cargo bench --locked --features ropey --bench word_motions -- --verify
cargo bench --locked --features ropey --bench word_motions -- --verify --holdout

Expect lower time per operation for backward-word and forward-word-end scans. Compare the verification stdout from both revisions byte for byte, including the holdout run covering CRLF, combining marks, emoji sequences, and EOF.

All 36,600 resolver observations matched the baseline. Rust tests passed with default features and Ropey. The local conformance run passed 393/393 cases on installed Neovim 0.12.2 with its version assertion adjusted in memory. The existing reference CI job runs the repository's pinned Neovim 0.12.1.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T00:54:54.133119Z ab00961 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@fcoury
fcoury merged commit 29984df into main Nov 26, 2026
6 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 26, 2026
@fcoury
fcoury deleted the perf/reuse-word-grapheme-offsets branch November 26, 2026 20:49
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