perf: remove unnecessary clones in a hot path - #3580
Conversation
Fossier: Manual Review Requested
Score BreakdownTotal Score: 51.3/100 | Confidence: 100% | Outcome: REVIEW
|
7f06ce7 to
627e69d
Compare
Unify all atuin-client benchmarks under a single harness with shared deterministic utilities (seeded StdRng, fixed timestamp). Add reorder_fuzzy (100/200/500/1k/10k) benchmarks. Restructure existing record store benchmarks to use shared _util modules.
reorder() received Vec<A> by value (already owned) but cloned it before sorting. Remove the clone, capture len before the mutable sort borrow, and drop the Clone trait bound.
627e69d to
59c6c20
Compare
Greptile SummaryRemoves an unnecessary
Confidence Score: 5/5Safe to merge — the only production code change is a one-function refactor in ordering.rs with identical semantics and measurable gains. The ordering change is mechanically correct: length is immutable across sort, so pre-capturing it is equivalent to the previous res.len() call. Benchmark restructuring is additive and isolated to dev-dependencies. No files require special attention. Important Files Changed
Reviews (1): Last reviewed commit: "perf: remove unnecessary Vec clone in fu..." | Re-trigger Greptile |
ellie
left a comment
There was a problem hiding this comment.
nice catch! one clone made a big difference. thank you!
### Bug Fixes - *(ai)* Dispatch skills registered in the slash command registry ([#3593](#3593)) - *(ci)* Fossier install in scan workflow ([#3485](#3485)) - *(i18n)* Fix typos in Russian localization ([#3575](#3575)) - *(nu)* Use `char -u 1b` for ESC in OSC 133 sequences ([#3530](#3530)) - *(nu)* Suppress error when `ATUIN_HISTORY_ID` is missing in `pre_prompt` hook ([#3587](#3587)) - *(pi)* Observe tool events instead of registering a bash tool ([#3557](#3557)) - *(pty-proxy)* Set `$SHELL` to the spawned shell ([#3548](#3548)) - *(search)* Fix terminal clearing with latest Ratatui ([#3578](#3578)) - *(sync)* Skip records that fail to decrypt or decode instead of failing the whole store ([#3569](#3569)) - Atuin hangs when attempting to spawn daemon from Ctrl+R invocation ([#3502](#3502)) - Capture session ID from stream headers rather than final event ([#3531](#3531)) - Doctor resiliency fo runknown platforms + openbsd warning ([#3551](#3551)) - Double input on arrow keys in AI setup prompt on Windows ([#3552](#3552)) - Exclude AI agent commands from zsh-autosuggestions ([#3567](#3567)) - Silence shellcheck SC2016 on literal `$all-user` author filter - Respect `store_failed` when using daemon ([#3571](#3571)) ### Documentation - Highlight `Ctrl-r` keybinding on docs page ([#3489](#3489)) - Document store purge workflow ([#3544](#3544)) - Fix command example typo in documentation ([#3536](#3536)) - Make commented-out lines in `config.toml` match real defaults ([#3583](#3583)) - Add fish shell cleanup step to uninstall instructions ([#3582](#3582)) ### Features - *(doctor)* Add whether daemon is enabled to `doctor` output ([#3572](#3572)) - *(pty-proxy)* Add `--shell` flag to override the spawned shell ([#3327](#3327)) - Setup fossier to stop bot slop prs ([#3482](#3482)) - Capture command output + expose to new `atuin_output` tool ([#3510](#3510)) - Cache user contexts on load until `/reload` ([#3525](#3525)) - Create database integration tests for atuin-server ([#3514](#3514)) - Add `/model` slash command for changing models ([#3576](#3576)) - Add mcp server for history tools and expand search filters ([#3581](#3581)) - Add status bar with model and usage information ([#3591](#3591)) ### Miscellaneous Tasks - *(rustdoc)* Fix Rustdoc warnings ([#3585](#3585)) - *(warnings)* Fix compile warnings with latest dependencies ([#3586](#3586)) - Vouch for all existing contributors ([#3486](#3486)) - Update GitHub app token format - Update to Rust 1.96.1 ([#3568](#3568)) - Adopt `derive_more` to reduce boilerplate across the codebase ([#3573](#3573)) ### Performance - *(search)* Scan history by recency until N unique ([#3553](#3553)) - Add `synchronous(Normal)` + `optimize_on_close` to record store SQLite ([#3577](#3577)) - Remove unnecessary clones in a hot path ([#3580](#3580)) ### Refactor - Implement `From<sqlx::Error>` and clean up `fix_error` ([#3484](#3484)) - Pull `fn into_utc` into `atuin-server-database` crate ([#3487](#3487))
This PR adds two commits:
crates/atuin-client.reorder_fuzzywhich avoids an unnecessary clone.Hand-rolled PR (I hated claude's output).
Benchmarking
I did a couple more changes to benchmarking.
rand, but I realized this is pretty bad for benchmark reproducibility, so I created a newBenchCtxutility which is a more stable random number generator (and a dumping ground for similar things where we want stability, another example in this PR being the "now" timestamp).1sfrom5s.Optimization
Pretty bog-standard removal of a potentially large clone.
Results
Tested on an M4 mac.
Before
After
Comparison
Checks