Repository navigation
timeout: stop parsing options after DURATION - #15189
SichenLiang wants to merge 2 commits into
Conversation
|
GNU testsuite comparison: |
paoValle
left a comment
There was a problem hiding this comment.
I checked the two things that looked risky in this shape:
options::DURATIONis still used, as the firstvalue_namesentry, so droppingArg::new(options::DURATION)does not leave it dead.operands.next().unwrap()is safe today:COMMANDisrequired(true)withnum_args(2..), soConfig::fromcannot be reached with fewer than two values. A short comment on that unwrap naming the guarantee would keep a later edit tonum_argsfrom silently turning it into a panic.
The rewrite of test_zero_timeout is right: -s0/-k0 placed after the duration used to be swallowed as timeout options, which GNU would have run as the command. test_option_like_command_after_duration covers the shapes I would have asked about (-X, -s KILL true, --help, --, -k1, and -v still being an option before DURATION).
One red check, not this change: Run memory benchmarks for uu_timeout (CodSpeed) failed inside the memory tracker with watcher mapping dev=... ino=... not found in stopped pid ...'s maps; ... (inode-namespace mismatch, e.g. overlayfs?). The CodSpeed Performance Analysis check is red on other open PRs too (#15174, #15175, #15191), and this utility's benchmark calls uumain with ["0.02", "true"], i.e. options before DURATION only, so the CLI change is not implicated.
|
Added a comment above the unwrap naming the |
Merging this PR will improve performance by 23.61%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ⚡ | Memory | timer_expiry_latency[0.02] |
17 KB | 10.6 KB | +60.44% |
| ⚡ | Memory | timer_expiry_latency[0.005] |
17 KB | 10.6 KB | +60.42% |
| ⚡ | Memory | timeout_enforced |
16.5 KB | 10.3 KB | +60.42% |
| ⚡ | Memory | timeout_quick_exit |
16.2 KB | 10.2 KB | +58.71% |
| ⚡ |
Simulation | timeout_enforced |
181.5 µs | 162.1 µs | +11.94% |
| ⚡ |
Simulation | timer_expiry_latency[0.02] |
182.3 µs | 164.7 µs | +10.71% |
| ⚡ | Memory | timer_expiry_latency[0.001] |
84.9 KB | 76.8 KB | +10.46% |
| ⚡ |
Simulation | timer_expiry_latency[0.005] |
183 µs | 165.9 µs | +10.28% |
| ⚡ |
Simulation | timeout_quick_exit |
172.3 µs | 159.5 µs | +7.99% |
| ⚡ | Simulation | thirteen_39_bit_primes |
9.8 s | 9.1 s | +7.36% |
| ⚡ | Simulation | three_39_bit_primes |
498 ms | 468 ms | +6.41% |
| ⚡ |
Simulation | timer_expiry_latency[0.001] |
418.2 µs | 401.3 µs | +4.23% |
Tip
Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.
Comparing SichenLiang:timeout-stop-options-at-duration (739001f) with main (7bc1eb6)
Footnotes
-
54 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
paoValle
left a comment
There was a problem hiding this comment.
The comment is in 739001f7 and says the right thing — COMMAND is required(true) with num_args(2..), so the get_many has at least two values and the next().unwrap() cannot panic. Nothing else left from me on the code.
One check on the head is red and it is not this change: Tests (wasm32-wasip1, --cfg wasi_runner) fails on test_date::test_date_format_locale_date_and_time (2722 passed, 1 failed) — the date test's locale lookup under wasm, nothing in timeout. The run is from 2026-10-10 and the branch has not been pushed since, so a re-run would probably clear it if you want the board green before a merge.
Clap kept parsing timeout options after DURATION, so a command beginning with '-' was treated as another timeout option instead of COMMAND. Make DURATION the first value of a trailing <duration> <command>... argument, with every later value passed to the command. Options before DURATION are unchanged. This changes the help layout and the wording of the missing-operand error. Remove the timeout-help-command translations that are no longer used.
`COMMAND` is required and the trailing argument has `num_args(2..)`, so `Config::from` always receives both DURATION and at least one command argument. Document that guarantee next to the unwrap.
739001f to
2c550c3
Compare
GNU treats the first argument after DURATION as COMMAND even when it starts with
-. uutils kept parsing timeout options there instead.DURATION is now the first value of one trailing
<duration> <command>...argument. Once clap reaches it, everything after that belongs to the command. Options before DURATION still work as before.For example, these now both exit 127, matching GNU:
--helpnow shows<duration> <command>...as one argument. The missing-operand wording changes too, but its exit status is still 125. The unusedtimeout-help-commandtranslations are removed. Keeping the old two-part help layout would mean splitting the arguments again by hand, about 30 more lines just for the layout.Closes #15188