uucore: Remove ARGV cache#13276
Conversation
sylvestre
left a comment
There was a problem hiding this comment.
the AI comment #0 isn't useful.
Please write it for a human as I am not an AI
|
Please update comment 0 |
|
GNU testsuite comparison: |
Merging this PR will improve performance by 5.72%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ⚡ | Simulation | complex_relative_date |
147.1 µs | 135.7 µs | +8.43% |
| ⚡ | Simulation | hostname_ip_lookup[100000] |
108.8 µs | 100.9 µs | +7.74% |
| ⚡ | Simulation | unexpand_large_file[10] |
291.9 ms | 282.3 ms | +3.41% |
| ⚡ | Simulation | unexpand_many_lines[100000] |
139.3 ms | 134.7 ms | +3.41% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing AnuthaDev:arghh-alloc (1155881) with main (871b80c)
Footnotes
-
46 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. ↩
|
Updated the Summary section in description (if that's what you meant by comment 0) |
|
this one: |
|
i still would like comment #0 to be shorter |
|
Improved the comment. Will create a separate PR to add a memory benchmark. Please review. |
i am waiting for this to review this PR |
|
RAM usage is reduced and already catched by benches https://app.codspeed.io/uutils/coreutils/branches/AnuthaDev%3Aarghh-alloc?utm_source=github&utm_medium=comment-v2&utm_content=button&q=mode%3Amemory |
|
@sylvestre Please let me know if the existing benchmark pointed out by @oech3 is enough or I need to add a separate benchmark |
|
ok, thanks |
|
@sylvestre I can see that you have enabled auto-merge, but its still pending on your approval since you had requested changes earlier. |
|
@sylvestre You need to click on "Approve PR" for it to get merged. Its blocked due to your earlier review.
|

Problem
uucorekeeps the CLI arguments cached in a static variable (ARGV), stating that repeatedly callingenv::args_osis expensive. Howeverenv::args_osis only called once during the binary lifecycle. Storing theARGVis useless overhead.Fix
ARGVvariable and added a different mechanism to initializeUTIL_NAMEandEXECUTION_PHRASE.init_util_name(),init_execution_phrase()that use the result of the firstargs_oscall to set these variables. This is to prevent an additional call toargs_osfor determining these values.get_or_initfor these values instead of panicking on uninitialized values so any downstream users ofuucorekeep working, albeit with a performance hit.Breaking changes
Two semantic changes for downstream consumers of the
uucorecrate:uucore::args_os()is no longer cheap to call repeatedly. It previously returned clones from a process-lifetime cache; it now copies all of argv (and re-expands globs viawildon Windows) on every call. Call it once and reuse the result.init_*functions, those values win over derivation from argv. Callers that never init see identical behavior to before.Measurements
printf "00 %.0s" {1..100000} > args.txtmain:This PR:
GNU echo:
The uutils version still allocates
332times more (down from653times), still lots of scope for reducing allocations.Impact
This change reduces memory allocation for all the coreutils binaries. The savings scale with argv: total allocations drop by one full argv copy, and the duplicate no longer persists for the process lifetime.
Practical benefit: Calling
ls pattern*in a directory with a large number of items matching the pattern allocates much less.Testing