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 — chore(perf): say when the clap ratio slides, and record why the deriv… · jdx/usage@af2495d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • derive/src
    • codegen.rs
  • tasks
    • perf-shadow.sh
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎derive/src/codegen.rs‎

Copy file name to clipboardExpand all lines: derive/src/codegen.rs
+20-4Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,10 +1338,6 @@ fn flag_arm(cli: &Cli, i: usize, field: &Field) -> TokenStream {
13381338
}
13391339
}
13401340

1341-
/// Whether another occurrence is a command-line mistake rather than another value.
1342-
///
1343-
/// Counts and collections repeat by definition, and `var` explicitly opts a value-taking flag
1344-
/// into repetition. Every other flag matches clap's default of one occurrence.
13451341
/// Whether a repeat of this flag is only a duplicate *within one command*.
13461342
///
13471343
/// A `global` flag is in scope for every descendant, and clap lets it be given again on a
@@ -1365,6 +1361,26 @@ fn reset_per_level(cli: &Cli) -> TokenStream {
13651361
quote!(#(#resets)*)
13661362
}
13671363

1364+
/// Whether another occurrence is a command-line mistake rather than another value.
1365+
///
1366+
/// Counts and collections repeat by definition, and `var` explicitly opts a value-taking flag
1367+
/// into repetition. Every other flag matches clap's default of one occurrence.
1368+
///
1369+
/// **This is stricter than the grammar, deliberately.** The corpus specifies the opposite for a
1370+
/// *spec-driven* parse — `long-repeated-keeps-the-last` says "a repeat is a correction, typically
1371+
/// a wrapper appending to a command line it did not write" — and usage-argv's parser and
1372+
/// usage-lib both honour that. The rule lives here, in the derive's post-binding layer, and
1373+
/// nowhere else: `Error::DuplicateFlag` is constructed at one call site, in this file.
1374+
///
1375+
/// Kept, because the two cases are not the same case. A spec parsed at run time may well be
1376+
/// describing someone else's command line, which is the wrapper the corpus has in mind. A
1377+
/// derived CLI is an authored, fixed surface, where `--jobs 1 --jobs 2` is far likelier to be a
1378+
/// mistake than an amendment — and it is what clap does, so an adopter replacing clap sees no
1379+
/// change. Dropping it would make a derived binary quietly accept a line clap rejects today,
1380+
/// which is the direction that costs an adopter rather than the one that helps.
1381+
///
1382+
/// Recorded because it looks like an inconsistency and is not one. `differential.rs` in the gate
1383+
/// carries the same note from the other end.
13681384
fn rejects_duplicate(field: &Field) -> bool {
13691385
matches!(field.kind, Kind::Flag { .. })
13701386
&& !matches!(field.shape, Shape::Count | Shape::Many)
Collapse file

‎tasks/perf-shadow.sh‎

Copy file name to clipboardExpand all lines: tasks/perf-shadow.sh
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ verify() {
6666
fi
6767
}
6868

69+
# The ratio against clap this file expects to hold, and below which it says so.
70+
#
71+
# Not a gate — the workflow runs this with `|| true`, and a shared runner is no place to fail a
72+
# build on an instruction count. It is an annotation, because the alternative turned out to be
73+
# nobody noticing: the number went from 117x to 97x across a run of feature work, unremarked,
74+
# because the only place it appeared was one line of a report nobody diffs. clap is flat, so the
75+
# movement was ours.
76+
#
77+
# 80 rather than 117: the point is to catch a slide, not to pin the current figure. A parse that
78+
# is only 80x cheaper than clap's has stopped being the thing this project claims, and that is
79+
# worth a sentence in the log before it is worth an argument about the target.
80+
CLAP_RATIO_FLOOR=80
81+
6982
# Two significant figures either side of the decimal point, so a framework within a factor
7083
# of usage reads as 1.5x rather than 1x and one three orders away still reads cleanly.
7184
ratio() {
@@ -119,3 +132,20 @@ bpaf_cold=$(cold parse-n-bpaf)
119132
} >"$tmp"
120133

121134
cat "$tmp" >"$out"
135+
136+
# Said after the report is written, so a failure here cannot leave the comment truncated — the
137+
# same reason the table is built in a temporary file.
138+
#
139+
# `::warning::` when running under GitHub Actions, a plain line otherwise, so the same script is
140+
# useful at a terminal.
141+
clap_ratio=$(awk -v a="$clap_cold" -v b="$usage_cold" 'BEGIN { printf "%d", a / b }')
142+
if [ "$clap_ratio" -lt "$CLAP_RATIO_FLOOR" ]; then
143+
message="the parse is ${clap_ratio}x cheaper than clap's, under the ${CLAP_RATIO_FLOOR}x this\
144+
file expects. clap is flat, so a fall here is usage getting more expensive rather than clap\
145+
getting cheaper. See tasks/perf-shadow.sh."
146+
if [ -n "${GITHUB_ACTIONS:-}" ]; then
147+
echo "::warning title=Shadow ratio below floor::$message"
148+
else
149+
echo "warning: $message" >&2
150+
fi
151+
fi

0 commit comments

Comments
0 (0)
You are visitor 01402792 — 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.