Skip to content

uucore, expr: centralize regex in uucore - #14531

Open
wtcpython wants to merge 1 commit into
uutils:mainfrom
wtcpython:uucore-regex
Open

wtcpython wants to merge 1 commit into
uutils:mainfrom
wtcpython:uucore-regex

Conversation

@wtcpython

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread Cargo.toml Outdated
num-prime = "0.5.0"
num-traits = "0.2.19"
fancy-regex = { version = "0.19.1", default-features = false, features = [
fancy-regex = { version = "0.19.2", default-features = false, features = [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps we could move the feature selection to src/uucore/Cargo.toml

@codspeed

codspeed Bot commented Sep 13, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 3.77%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 14 regressed benchmarks
✅ 353 untouched benchmarks
⏩ 50 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory factor_multiple_u64s[2] 88.8 KB 92.9 KB -4.4%
Memory hostname_basic 91 KB 95.1 KB -4.3%
Memory seq_custom_separator 93.1 KB 97.2 KB -4.21%
Memory wc_lines_extreme_line_lengths[(100000, 200)] 99.7 KB 103.8 KB -3.94%
Memory nl_many_lines[100000] 100.9 KB 105 KB -3.9%
Memory unexpand_many_lines[100000] 101.7 KB 105.8 KB -3.87%
Memory expand_custom_tabstops[50000] 101.7 KB 105.8 KB -3.86%
Memory cut_characters_long_lines 103.2 KB 107.3 KB -3.81%
Simulation hostname_basic 427.3 µs 443.8 µs -3.72%
Memory fold_custom_width[50000] 110.7 KB 114.8 KB -3.56%
Memory split_numeric_suffix 115.2 KB 119.3 KB -3.43%
Memory df_deep_directory 115.4 KB 119.5 KB -3.42%
Memory join_custom_separator 120.7 KB 124.8 KB -3.28%
Memory cksum_multiple_files 125.9 KB 130 KB -3.15%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing wtcpython:uucore-regex (cd53de5) with main (94811cc)2

Open in CodSpeed

Footnotes

  1. 50 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.

  2. No successful run was found on main (c6b9e4f) during the generation of this report, so 94811cc was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@xtqqczze

This comment was marked as outdated.

@github-actions

github-actions Bot commented Sep 13, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/date/date-locale-hour (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/tail-n0f (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/seq/seq-epipe is now passing!

@oech3

This comment was marked as resolved.

@wtcpython
wtcpython force-pushed the uucore-regex branch 2 times, most recently from 846bee8 to 20880e0 Compare September 14, 2026 00:19
@wtcpython wtcpython changed the title uucore, expr: centralize regex in uucore and adopt fancy-regex leftmost-longest uucore, expr: centralize regex in uucore Sep 14, 2026
@wtcpython
wtcpython marked this pull request as ready for review September 14, 2026 00:23
Copilot AI lite review requested due to automatic review settings September 14, 2026 00:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings September 15, 2026 14:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sylvestre

Copy link
Copy Markdown
Contributor

@codspeedbot fix this regression

@codspeed

codspeed Bot commented Sep 16, 2026

Copy link
Copy Markdown

@codspeedbot fix this regression

Fixed in 3d05af4.

What the report was actually showing

The regression was real, not noise: every memory benchmark in the tree gained exactly the same amount — +16 allocations, +4,752 bytes allocated, +4,187 bytes peak — including utilities that never compile a regex. Only the cheapest benchmarks crossed the reporting threshold, which is why the list looks arbitrary. I reproduced it locally with the CodSpeed CLI:

hostname_basic (simulation) instructions
main (94811cc) 318,823
this branch 335,034 (+5.1%)

Cause

uucore/locales/errors/en-US.ftl is parsed on the first lookup that misses every ordinary bundle. That is meant to be an error path only, but a binary that cannot resolve its own strings misses on every id it asks for — and a bench binary calling uumain directly is exactly that. So every benchmark was parsing the whole error resource: 106k of the 319k instructions hostname_basic measures, plus 16 allocations that are never freed.

Growing that shared file therefore charges every benchmark. The eight new regex-error-* messages are ~430 bytes of Fluent, and that is what the 3–4% you saw is: hostname paying for strings it can never reach.

Fix

The ids the error resource defines are now generated at build time and checked before the bundle is built, so a lookup that cannot be in there costs a matches! instead of a parse. The regex centralization itself is untouched.

hostname_basic (simulation) instructions
main (94811cc) 318,823
this branch before the fix 335,034
this branch with the fix 212,632

The regression is gone, and every benchmark drops the error-resource parse it was never supposed to pay — expect improvements across the board in the next report rather than a flat comparison.

Validation: uucore unit tests, the build-script tests, and the expr (164), cksum (388) and printf (143) integration tests pass; cargo fmt and cargo clippy -p uucore --all-targets are clean. expr still reports its regex diagnostics in English and in French (expr: Unmatched ( or \( / expr: Parenthèse ouvrante ( ou \( non appariée), and the expr benchmarks are unchanged (1,448,685 vs 1,448,761 on main).

One caveat on the original report: its base was 94811cc rather than your merge base, and several benchmarks were compared across different CPU models. That did not affect this diagnosis — the memory numbers are byte-identical on both base runs — but it is worth reading the "Environment Differences" section before trusting any sub-10% simulation move on this repo.

Summary
  • Warming up the performance wizard...
  • Investigate the reported regression — Every util's bench gained exactly +16 allocations / +4.2 KB peak and ~5% instructions, including utils that use no regex — a fixed startup cost, not noise.
  • Reproduce locally and locate the extra allocations — Reproduced with the CodSpeed CLI: hostname_basic 318,823 -> 335,034 instructions. The cost is a full Fluent parse of uucore/locales/errors/en-US.ftl, which every bench binary triggers because it calls uumain directly and cannot resolve its own utility strings.
  • Fix the regression — The error-only strings are now consulted only for the ids they define (list generated at build time), so a lookup that misses every bundle no longer parses the resource.
  • Validate the fix and push — hostname_basic 212,632 instructions (-33% vs main), expr benches unchanged; uucore, expr, cksum and printf tests plus fmt/clippy pass. Pushed as 3d05af4.
  • Handling comment — Comment handling finished successfully

Was this response helpful? React with 👍 or 👎 to help us improve CodSpeedBot.

Copilot AI review requested due to automatic review settings September 16, 2026 14:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@SuperMuel

Copy link
Copy Markdown

@sylvestre The agent successfully pushed wtcpython@3d05af4 to the PR’s source branch, but GitHub did not synchronize the PR with the new commit. I’m investigating 👀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants