Skip to content

perf(project): move completed keys into keyboard overlay groups - #3197

Merged
richiemcilroy merged 1 commit into
CapSoftware:mainfrom
vedanth-jadhav:perf/move-completed-keyboard-groups
Oct 25, 2026
Merged

richiemcilroy merged 1 commit into
CapSoftware:mainfrom
vedanth-jadhav:perf/move-completed-keyboard-groups

Conversation

@vedanth-jadhav

@vedanth-jadhav vedanth-jadhav commented Oct 25, 2026 •

Copy link
Copy Markdown

group_key_events clones every completed group's key vector, including each key's owned String, then clears the working vector. The GPUI editor calls this through generate_project_keyboard_segments when building keyboard overlays; legacy keyboard synchronization uses it too.

Move the key entries into an exactly sized output vector with Vec::append, retaining the working vector's allocation for the next group. This removes the deep key-text copies without repeatedly growing a fresh working vector. Group text handling, grouping decisions, modifier state, timestamps, IDs, and APIs are unchanged. The production change is three call-site substitutions and one small private helper.

Measurements

Baseline f510acfa1 against this branch. Linux x86_64 container, AMD EPYC 9V74, two-CPU quota, process pinned to CPU 0, Rust 1.88.0; repository release profile (opt-level=s, thin LTO, one codegen unit).

Five alternating independent processes per version, 25 samples per fixture after three warmups; table shows medians of process p50s. Positive reduction means faster. Fixtures model ten keys/second, typing hello separated by spaces; the shortcut variant presses/releases Meta periodically. Ten fixture sizes/modes were measured, from 100 to 36,000 keys.

Fixture Grouping before → after Reduction Track generation before → after Reduction
typing, 1,000 keys 0.111245 → 0.082202 ms +26.1% 0.574179 → 0.583371 ms -1.6%
typing, 36,000 keys 3.871336 → 3.287110 ms +15.1% 25.169635 → 23.217586 ms +7.8%
shortcuts, 1,000 keys 0.136932 → 0.121168 ms +11.5% 0.670519 → 0.643980 ms +4.0%
shortcuts, 36,000 keys 5.311675 → 4.919214 ms +7.4% 27.031934 → 26.233404 ms +3.0%

The 36,000-key fixture represents about one hour and 72,000 captured events (75,600 with shortcuts). The complete generate_project_keyboard_segments API measurement includes warm event-file reads, binary decoding, projection, and grouping. It excludes recording metadata loading, app dispatch, rendering, and output destruction. No native UI/FPS claim is made. The 1,000-key plain-typing generation control is 1.6% slower; small whole-path changes should not be overstated.

Every process serialized all grouped/generated tracks. All ten fixtures and both APIs match the baseline byte-for-byte across all runs (aggregate SHA256 df803d338e6e50f1ccabe2f095dfe96160de20f9657cfacb9c751cd407cd0ebd). In the one-hour plain-typing fixture, 6,000 completed words each contain five key strings, so this avoids 30,000 deep string copies while preserving output sizes and the scratch vector's capacity.

Correctness and checks

A new normal test covers group completion on a nearby space, a distant space, a new key after a pause, and a modifier. It pins the completed group's full serialized contents, key offsets and times after subsequent reuse, and verifies the source events are unchanged. Existing modifier, special-key, backspace, projection, binary compatibility, and timing tests pass.

  • cargo fmt --all and cargo fmt --all --check
  • cargo check -p cap-project --locked
  • cargo test -p cap-project --locked: 179 library tests and 4 integration tests passed; 4 existing benchmarks ignored.
  • cargo clippy -p cap-project --all-targets --locked -- -D warnings
  • git diff --check

Reproduction

Use this branch's benchmark source on both revisions. It increases warmups/samples and selects the appropriate p95 sample for the larger sample count; the comparison above uses p50.

cargo build -p cap-project --release --locked --example keyboard-grouping-benchmark -j 2
CAP_KEYBOARD_BENCH_OUTPUT=/tmp/keyboard-output.json   taskset -c 0 target/release/examples/keyboard-grouping-benchmark

Save baseline/head binaries separately, alternate five processes each, compare the output files, and take medians of the p50 columns. The existing --check-scaling option remains available. Raw samples/outputs are kept outside the production repository.

Risk is limited to ownership during group completion. Vec::append empties the accumulator and transfers the original owned entries; later clearing/reuse cannot modify completed groups. No cache, concurrency, or public data layout changes. This is separate from the merged modifier-scan/indexing optimizations and the pending key-symbol/keycap UI changes.

Publication validation: rebased onto ec15b9840; 183 scoped tests passed, plus formatting, check, and strict all-target Clippy. Benchmarks above were recorded before this rebase; the production paths changed by this PR remain as measured.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no actionable issues were found.

Summary

Moves completed groups’ keys instead of cloning their strings, while keeping the working vector’s allocation.

  • Completed keyboard groups move their key entries instead of copying them.

Reviews (1) · Last reviewed commit: "perf(project): move completed keyboard k..." · Reviewed by Greptile

@vercel

vercel Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Someone is attempting to deploy a commit to the Cap Software Inc Team on Vercel.

A member of the Team first needs to authorize it.

@richiemcilroy
richiemcilroy merged commit a05ccfa into CapSoftware:main Oct 25, 2026
59 of 63 checks passed
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.

2 participants