Skip to content

ls, df: preserve suffix-only block size units - #14390

Open
Socialpranker wants to merge 2 commits into
uutils:mainfrom
Socialpranker:feat/ls-df-blocksize-suffix
Open

Socialpranker wants to merge 2 commits into
uutils:mainfrom
Socialpranker:feat/ls-df-blocksize-suffix

Conversation

@Socialpranker

@Socialpranker Socialpranker commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

ls -l --block-size=K and df --block-size=K printed a bare number where GNU
echoes the unit back: 1K, not 1. A spec with a leading number
(--block-size=1K, --block-size=1024) only sets the divisor and echoes
nothing. Same for LS_BLOCK_SIZE, BLOCK_SIZE, BLOCKSIZE, DF_BLOCK_SIZE.
-h/--si are unaffected.

This is the gap noted in #14330's description; #13655 fixes the same defect for
du (it touches only du.rs, no conflict).

Two commits: df (+ the shared uucore helpers) first, ls on top. Each
builds and tests on its own.

Verified byte-for-byte against GNU coreutils 9.11 (gls/gdf) over 12
block-size specs x ls -l, -s, total, and the env vars. New tests in
test_ls.rs, test_df.rs, plus unit tests in uucore.

Prepared with AI assistance (Claude Sonnet 5, via Claude Code), per the AI
policy in CONTRIBUTING.md. GNU behavior came from running the binary, not from
reading GPL source.

@sylvestre

Copy link
Copy Markdown
Contributor

could you please make comment #0 a bit shorter ? nobody likes reading long llm output ;)

Comment thread src/uu/df/src/blocks.rs Outdated
Comment on lines +127 to +132
/// The default variant is `Bytes(1024, None)`.
///
/// The second field is the GNU-style display suffix (e.g. `"K"`) to echo
/// back next to a scaled number, set only when the block size was given as
/// a suffix-only spec (`--block-size=K`) rather than a numeric one
/// (`--block-size=1K`, `--block-size=1024`).

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.

make this comment shorter

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Cut to 3 lines with the example inline.

Comment thread src/uu/ls/src/config.rs Outdated
fn resolve_block_sizes_from_env(opt_kb: bool) -> (u64, u64) {
match parse_block_size::block_size_from_env(&["LS_BLOCK_SIZE", "BLOCK_SIZE"]) {
parse_block_size::BlockSizeEnv::Found(size) => {
/// `BLOCKSIZE` only affects the allocation display (`-s`), not file sizes.

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.

same, this comment is too long

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Cut to 4 lines.

BlockSizeEnv::NotSet
}

/// Extract the display suffix from a block-size spec, if the spec is

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.

i don't think we need 14 lines of comments
esp when they don't follow rustdoc format or provide an example

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Down to 2 lines plus a rustdoc example.

Comment thread src/uu/ls/src/config.rs Outdated
const DEFAULT_FILE_SIZE_BLOCK_SIZE: u64 = 1;

/// Resolve `(file_size_block_size, block_size)` from environment variables.
/// The block sizes `ls` displays with, plus the display suffixes that go

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.

please do a gh stack and move ls in the second commit of the stack

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Split: df + the uucore helpers first, ls on top. Each commit builds and tests alone. Happy to split into two PRs if you'd rather have a real stack.

@github-actions

github-actions Bot commented Sep 5, 2026 •

Copy link
Copy Markdown

GNU testsuite comparison:

Congrats! The gnu test tests/env/env is no longer failing!
Congrats! The gnu test tests/misc/usage_vs_getopt is no longer failing!

@Socialpranker
Socialpranker force-pushed the feat/ls-df-blocksize-suffix branch from 0d0a1e1 to b2e2527 Compare September 5, 2026 19:46
@Socialpranker

Copy link
Copy Markdown
Contributor Author

Comments trimmed throughout the diff (longest was 14 lines, now 2 + an example), and split into two commits: df + uucore helpers, then ls. Body shortened too.

@codspeed

codspeed Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will improve performance by 53.08%

2 warnings, 1 note

⚠️ 121 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ 12 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

ℹ️ 1 benchmark has no flamegraph

The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

See affected benchmarks

⚡ 14 improved benchmarks
✅ 391 untouched benchmarks
🆕 8 new benchmarks
⏩ 70 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ Memory factor_small_factors_and_a_large_prime 104.8 KB 15.4 KB ×6.8
⚡ CPU Simulation split_lines 14.4 ms 4.3 ms ×3.3
⚡ CPU Simulation split_numeric_suffix 14.6 ms 4.5 ms ×3.2
⚡ CPU Simulation factor_small_factors_and_a_large_prime 1,012.7 µs 682 µs +48.48%
⚡ CPU Simulation join_partial_overlap 18.7 ms 15.1 ms +23.41%
⚡ Memory cp_recursive_deep_tree[(120, 4)] 699.2 KB 581.2 KB +20.31%
⚡ CPU Simulation join_full_match 21.8 ms 18.3 ms +19.18%
⚡ CPU Simulation join_french_locale 21.8 ms 18.3 ms +19.14%
⚡ CPU Simulation join_unicode_locale 2.2 ms 1.8 ms +19.07%
⚡ CPU Simulation join_custom_separator 22.1 ms 18.8 ms +17.81%
⚡ CPU Simulation unexpand_large_file[10] 88.5 ms 83.4 ms +6.14%
⚡ CPU Simulation unexpand_many_lines[100000] 42.6 ms 40.2 ms +6.08%
⚡ CPU Simulation split_number_chunks_round_robin 30.3 ms 28.9 ms +4.87%
⚡ CPU Simulation split_bytes 781.9 µs 755.9 µs +3.43%
🆕 Memory factor_batch_of_largest_u64s N/A 796 KB N/A
🆕 Memory factor_batch_of_semiprimes N/A 199.5 KB N/A
🆕 Memory factor_batch_of_small_numbers N/A 7.5 MB N/A
🆕 Memory factor_batch_of_smallest_u128s N/A 885.4 KB N/A
🆕 CPU Simulation factor_batch_of_largest_u64s N/A 557.4 ms N/A
🆕 CPU Simulation factor_batch_of_semiprimes N/A 794.2 ms N/A
... ... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing Socialpranker:feat/ls-df-blocksize-suffix (aca83a4) with main (fca3de1)2

Open in CodSpeed

Footnotes

  1. 70 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 (50dfbbd) during the generation of this report, so fca3de1 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@sylvestre

Copy link
Copy Markdown
Contributor

the CI has been failing on this one for a while, could you please have a look? otherwise, i will close it, thanks

@Socialpranker
Socialpranker force-pushed the feat/ls-df-blocksize-suffix branch from b2e2527 to 629a107 Compare November 10, 2026 05:34
@Socialpranker

Copy link
Copy Markdown
Contributor Author

rebased on main. the red CI was the new clippy lint in uucore, main already allows it

@Socialpranker
Socialpranker force-pushed the feat/ls-df-blocksize-suffix branch from 629a107 to d19c107 Compare November 14, 2026 14:14
@sylvestre
sylvestre force-pushed the feat/ls-df-blocksize-suffix branch from d19c107 to aca83a4 Compare November 16, 2026 19:19
@Socialpranker
Socialpranker force-pushed the feat/ls-df-blocksize-suffix branch from aca83a4 to c17540f Compare November 18, 2026 09:48
@github-actions

Copy link
Copy Markdown

Binary size comparison:

Individual binary size comparison VS main (threshold: >=5% AND >=4 KB).

Total size of compared binaries: 155.49 MB (+104 KB, +0.07%)

Significant per-binary changes:
  env     1.20 MB ->    1.28 MB  (+80 KB, +6.51%)

@Socialpranker

Copy link
Copy Markdown
Contributor Author

MSYS is also red on main (run 44410185358, same job fails in the Publish step), so the MSYS failure here is not from this diff.

GNU echoes the unit back next to the number when --block-size (or
DF_BLOCK_SIZE/BLOCK_SIZE/BLOCKSIZE) is given as a bare unit
(--block-size=K -> "1K"), but not when a numeric multiplier is given
(--block-size=1K or --block-size=1024 -> "1"). uutils printed a bare
number in both cases.

Adds suffix_from_parsed_block_size and block_size_from_env_with_suffix
to uucore's parse_block_size; df's BlockSize now carries an optional
display suffix, which also lets the header keep a full IEC spelling
(--block-size=KiB -> "1KiB-blocks").
Same rule as the previous commit, applied to ls: --block-size=K (and
LS_BLOCK_SIZE/BLOCK_SIZE/BLOCKSIZE) echoes the unit next to the size,
--block-size=1K does not.

ls tracks the file-size and allocation suffixes separately, since
BLOCKSIZE only affects the allocation column (-s and the total line)
and must not leak into the -l size column. -k resets the allocation
block size and its unit, leaving a file-size unit from the environment
alone, matching GNU.
@sylvestre
sylvestre force-pushed the feat/ls-df-blocksize-suffix branch from c17540f to d8a9d69 Compare November 19, 2026 18:56

This branch has not been deployed

No deployments
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.

2 participants