GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — perf(derive): fill the partial through &mut instead of returning it by jdx · Pull Request #980 · jdx/usage

Conversation

@jdx

@jdx jdx commented Aug 17, 2026 •
edited by cursor Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Owner

Partial is the whole CLI's worth of accumulator — every command's fields
inlined, recursively — so at mise's scale it is 11KB. read_argv, read and
parse_from each returned one by value, and every hop was a memcpy of all of
it: four moves, and 87% of a parse spent copying a struct of which all but one
command's worth goes untouched.

read_argv_into and read_into take &mut Partial instead, so the entry point
builds the accumulator in the frame that will consume it and nothing moves it.
The by-value read_argv and read stay as wrappers over them, so no generated
API changes shape.

Measured with cachegrind against the mise shadow (211 commands, 711 flags), one
cold parse of mise use -g node@20:

before  63,822 instructions    81x fewer than clap
after   18,490 instructions   281x fewer than clap

One 11KB copy remains, the one that builds the partial: Subcommands::Partial
is a struct with a field per variant, so constructing it materialises every
command's accumulator whether or not that command was reached. Making it an
enum is the fix for that, and is a separate change.

Co-Authored-By: Claude Opus 5 [email protected]


Stack created with GitHub Stacks CLI • Give Feedback 💬

🤖 Generated with Claude Code


Note

Low Risk
Codegen-only change with preserved public wrappers; behavior should be identical aside from performance, though all generated binaries recompile.

Overview
Generated CLI parsing no longer returns the large Partial accumulator up the call stack on each hop. read_argv_into and read_into fill a caller-owned &mut Partial; parse_from, parse_from_with_settings, and the existing read / read_argv wrappers allocate once via #defaults and delegate to those helpers.

This removes repeated ~11KB moves on big trees (e.g. mise), where most of the struct is unused per invocation. Public generated APIs are unchanged—by-value read / read_argv still exist as thin wrappers.

Reviewed by Cursor Bugbot for commit 4d08769. Bugbot is set up for automated code reviews on this repo. Configure here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

greptile-apps[bot] reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@coderabbitai

coderabbitai Bot commented Aug 17, 2026

Copy link
Copy Markdown

Caution

Review failed

An error occurred during the review process. Please try again later.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
  • X
  • Mastodon
  • Reddit
  • LinkedIn

Comment @coderabbitai help to get the list of available commands.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Aug 17, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Instruction counts

benchmark trend instructions Δ wall (min) Δ
markdown █▇▇█▇██▃▁▁ 196,090,435 → 196,162,440 +0.04% 18.53 → 17.78ms -4.05%
startup ███████▁▁▁ 823,781 → 823,702 -0.01% 0.84 → 0.86ms +3.31%

No instruction-count regression above 1%.

Only instruction counts gate. Wall clock is shown for context — on identical hardware it moves 4-20% run to run.

Measured by tak — instruction-counted CLI benchmarks, stored in this repository's git notes.

Shadow comparison

Parsing mise use -g node@20 against a shadow of mise's committed spec.
Reported, not gated: the shadow grows as the derive learns to express more, so
what to watch is the ratio rather than either column.

usage clap ratio
instructions, cold parse 18502 5895248 318x
usage: argv -> struct                             652 ns      0.65 µs
clap: build tree + parse -> struct             499615 ns    499.62 µs
clap: parse -> struct, tree reused              23159 ns     23.16 µs
clap: build tree only                          310726 ns    310.73 µs

4d087691d7a7 vs 38bef2be9429 · measured on the runner, not pushed to the history.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jdx
perf(derive): fill the partial through &mut instead of returning it
4d08769
`Partial` is the whole CLI's worth of accumulator — every command's fields
inlined, recursively — so at mise's scale it is 11KB. `read_argv`, `read` and
`parse_from` each returned one by value, and every hop was a memcpy of all of
it: four moves, and 87% of a parse spent copying a struct of which all but one
command's worth goes untouched.

`read_argv_into` and `read_into` take `&mut Partial` instead, so the entry point
builds the accumulator in the frame that will consume it and nothing moves it.
The by-value `read_argv` and `read` stay as wrappers over them, so no generated
API changes shape.

Measured with cachegrind against the mise shadow (211 commands, 711 flags), one
cold parse of `mise use -g node@20`:

    before  63,822 instructions    92x fewer than clap
    after   18,490 instructions   319x fewer than clap

One 11KB copy remains, the one that builds the partial: `Subcommands::Partial`
is a struct with a field per variant, so constructing it materialises every
command's accumulator whether or not that command was reached. Making it an
enum is the fix for that, and is a separate change.

Co-Authored-By: Claude Opus 5 <[email protected]>


Measured after `cargo build --release` over the whole workspace, which is what
`mise run perf` does. A `-p gate` build unifies fewer features and reports clap
14% cheaper; usage's own figure is the same either way.
@jdx
jdx force-pushed the perf/partial-by-ref branch from 6a3c613 to 4d08769 Compare August 17, 2026 14:10
@jdx
jdx marked this pull request as ready for review August 17, 2026 17:17
@greptile-apps

greptile-apps Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR refactors generated CLI parsing to initialize Partial in the consuming stack frame and fill it through mutable references, avoiding repeated large value moves while retaining the existing by-value wrappers.

  • Adds generated read_argv_into and read_into helpers.
  • Routes parse_from and parse_from_with_settings through the in-place path.
  • Preserves default initialization, settings extraction, post-binding checks, error lifetimes, and final struct construction order.

Confidence Score: 5/5

The PR appears safe to merge with no actionable correctness or security defects identified.

The generated entry points continue to create a fresh accumulator, apply argv events, perform settings and post-binding work in the previous order, and expose no partially mutated state on errors.

Important Files Changed

Filename Overview
derive/src/codegen.rs Refactors generated parsing to mutate a caller-owned accumulator; reviewed paths preserve prior initialization, parsing, settings, validation, and construction semantics.

Reviews (1): Last reviewed commit: "perf(derive): fill the partial through &..." | Re-trigger Greptile

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jdx
jdx merged commit 3399281 into main Aug 17, 2026
10 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@jdx
jdx deleted the perf/partial-by-ref branch August 17, 2026 18:00
@mise-en-dev mise-en-dev mentioned this pull request Aug 17, 2026
chore: release v6.0.0 #795
Merged
jdx added a commit that referenced this pull request Aug 21, 2026
@jdx @claude
docs: correct the published parser performance numbers
83fddf0
The report and the plan both still described a regression that was diagnosed and
fixed on 2026-08-17, so the published figures understated the shipped parser by
roughly 8x.

Re-measured at mise's scale with the existing harness: 7,377 instructions
against clap's 6.31M (855x) and 0.69us against 544us, so all three original
gates still pass and by a wider margin than at launch.

The interesting part is why the number moved, because the earlier text read the
rise as the price of vocabulary and it was not. Two costs scaled with the whole
CLI rather than with what was typed: `Partial` is the entire CLI's accumulator
and was returned by value, so a parse copied 11KB four times and spent ~87% of
itself copying (#980, 63.8k -> 18.5k), and `Subcommands::Partial` was a struct
with a field per variant, so constructing it materialised all 211 commands'
accumulators to fill one (#981, 18.5k -> 4.2k). Because the accumulator was
copied per parse, every property the derive learned widened a struct already
being copied, so ordinary growth arrived multiplied.

The rest of the movement is the fixture rather than the parser, separated by
measuring one parser against both: 4,907 against the pre-refresh spec and 7,377
against the current one, which #1142 refreshed from mise's real typed tree.

Also corrects two stale claims. The plan said the ratio was unwatched and worth
a gate, but CLAP_RATIO_FLOOR=80 has warned on a slide since af2495d. And the
allocation note described `start` building every command's partial in the
present tense, which #981 ended.

The floor's own comment kept its history but no longer implies features caused
the slide, since that is the wrong thing for the next reader to conclude.

Co-Authored-By: Claude Opus 5 <[email protected]>
@jdx jdx mentioned this pull request Aug 21, 2026
docs: resolve remaining 6.x design decisions #1167
Merged
@BrewTestBot BrewTestBot mentioned this pull request Aug 22, 2026
usage 6.0.0 Homebrew/homebrew-core#300125
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@jdx
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.