Skip to content

yes, portable.rs: change BUF_SIZE to 32 KiB - #16313

Merged
sylvestre merged 1 commit into
uutils:mainfrom
oech3:patch-1
Nov 10, 2026
Merged

sylvestre merged 1 commit into
uutils:mainfrom
oech3:patch-1

Conversation

@oech3

@oech3 oech3 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor
> target/release/yes-32 |pv>/dev/null
[10.9GiB/s]
> target/release/yes-64 |pv>/dev/null
[6.44GiB/s]
> target/release/yes-16 |pv>/dev/null
[8.50GiB/s]

@oech3 oech3 changed the title portable.rs: change BUF_SIZE to 32 KiB yes, portable.rs: change BUF_SIZE to 32 KiB Nov 9, 2026
@sylvestre

Copy link
Copy Markdown
Contributor

makes wasm sad:


running 2 tests
Error: failed to run main module `/home/runner/work/coreutils/coreutils/target/wasm32-wasip1/debug/deps/uu_yes-03855c56f10202b5.wasm`
test tests::test_args_into_buf ... ok

Caused by:
    0: failed to invoke command default
    1: error while executing at wasm backtrace:
    0:  0x4aa1b - uu_yes-03855c56f10202b5.wasm!abort
    1:  0x46782 - uu_yes-03855c56f10202b5.wasm!std[6755ea078148a6bd]::sys::pal::wasi::abort_internal
    2:  0x4291d - uu_yes-03855c56f10202b5.wasm!std[6755ea078148a6bd]::process::abort
    3:  0x42e19 - uu_yes-03855c56f10202b5.wasm!__rustc[3d2f79520d6fa809]::__rust_abort
    4:  0x40bdc - uu_yes-03855c56f10202b5.wasm!__rustc[3d2f79520d6fa809]::__rust_start_panic
    5:  0x42cb0 - uu_yes-03855c56f10202b5.wasm!__rustc[3d2f79520d6fa809]::rust_panic
    6:  0x42019 - uu_yes-03855c56f10202b5.wasm!std[6755ea078148a6bd]::panicking::panic_with_hook
    7:  0x4146f - uu_yes-03855c56f10202b5.wasm!std[6755ea078148a6bd]::panicking::panic_handler::{closure#0}
    8:  0x413d7 - uu_yes-03855c56f10202b5.wasm!std[6755ea078148a6bd]::sys::backtrace::__rust_end_short_backtrace::<std[6755ea078148a6bd]::panicking::panic_handler::{closure#0}, !>
    9:  0x42efc - uu_yes-03855c56f10202b5.wasm!__rustc[3d2f79520d6fa809]::rust_begin_unwind
   10:  0x543d4 - uu_yes-03855c56f10202b5.wasm!core[3aca2c77b46c341]::panicking::panic_fmt
   11:  0x4fae4 - uu_yes-03855c56f10202b5.wasm!core[3aca2c77b46c341]::panicking::assert_failed_inner
   12:  0x4fb2d - uu_yes-03855c56f10202b5.wasm!core[3aca2c77b46c341]::panicking::assert_failed::<usize, usize>
   13:   0x220d - uu_yes-03855c56f10202b5.wasm!uu_yes[7aa4471caeb67229]::tests::test_prepare_buffer
   14:   0x1f8b - uu_yes-03855c56f10202b5.wasm!uu_yes[7aa4471caeb67229]::tests::test_prepare_buffer::{closure#0}
   15:   0x3268 - uu_yes-03855c56f10202b5.wasm!<uu_yes[7aa4471caeb67229]::tests::test_prepare_buffer::{closure#0} as core[3aca2c77b46c341]::ops::function::FnOnce<()>>::call_once
   16:   0x32e3 - uu_yes-03855c56f10202b5.wasm!test[f5c8449ceb760d21]::__rust_begin_short_backtrace::<core[3aca2c77b46c341]::result::Result<(), alloc[8b724565cfba7854]::string::String>, fn() -> core[3aca2c77b46c341]::result::Result<(), alloc[8b724565cfba7854]::string::String>>
   17:  0x1aef7 - uu_yes-03855c56f10202b5.wasm!<test[f5c8449ceb760d21]::types::RunnableTest>::run
   18:  0x1c252 - uu_yes-03855c56f10202b5.wasm!test[f5c8449ceb760d21]::run_test
   19:  0x19a60 - uu_yes-03855c56f10202b5.wasm!test[f5c8449ceb760d21]::console::run_tests_console
note: using the `WASMTIME_BACKTRACE_DETAILS=1` environment variable may show more debugging information
    2: wasm trap: wasm `unreachable` instruction executed

error: test failed, to rerun pass `-p uu_yes --lib`

@oech3

oech3 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor Author

I can simpliy add cfg, but it is very odd. @eduardomourar

@oech3
oech3 force-pushed the patch-1 branch 2 times, most recently from 801149f to 50a3535 Compare November 9, 2026 19:19
Comment thread src/uu/yes/src/platform/portable.rs Outdated
// it's possible that using a smaller or larger buffer might provide better performance
#[cfg(not(unix))] // small stack size?
pub(super) const BUF_SIZE: usize = 16 * 1024;
#[cfg(unix)]

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.

portable.rs isn't used on linux (linux.rs is), so which OS gave these numbers? could you please share a benchmark on macos/freebsd?

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.

I tested this on Linux by removing cfg.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

So, are these numbers representative of actual performance on any supported platform?

@oech3 oech3 Nov 9, 2026 •

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.

$ wasmtime '/tmp/dec/coreutils-wasm32-wasip1/16-yes.wasm'|pv>/dev/null
[2.66~2.70GiB/s]
$ wasmtime '/tmp/dec/coreutils-wasm32-wasip1/32-yes.wasm'|pv>/dev/null
[2.74~2.98GiB/s]

Comment thread src/uu/yes/src/platform/portable.rs Resolved
Comment thread src/uu/yes/src/platform/portable.rs Resolved
@eduardomourar

eduardomourar commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

I have confirmed that it is not caused by your changes. My guess is that it is an issue in wasmtime itself (or limitation of the resources/infra of GitHub Actions). I cannot get the actual host/guess error as it is never surfaced in the logs, though. Just for reference, I have raised this issue to track it: #16314.

@oech3

oech3 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Thankyou. Actually, it was caused by #16313 (comment) .

@xtqqczze

xtqqczze commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

To be honest, I'd rather default to a 8 KiB buffer size for the portable implementation, then raise it per platform as appropriate.

@oech3

oech3 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor Author

I don't agree. yes is used for generating test data & erasing strage device. But I'm fine with adding fast-path using small buf (1 page cache) for yes | script.sh case.

@xtqqczze

xtqqczze commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Rust standard library std::sys::io::DEFAULT_BUF_SIZE is 8 KiB, perhaps it could be increased upstream.

@sylvestre
sylvestre merged commit 2d38121 into uutils:main Nov 10, 2026
102 of 103 checks passed
@oech3
oech3 deleted the patch-1 branch November 10, 2026 22:18
@oech3

oech3 commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

Getting L2 cache size might interesting. But it needs additional syscall.

@xtqqczze

Copy link
Copy Markdown
Collaborator

What about using a stack-allocated buffer (for non-Linux)?

@oech3

oech3 commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

I want to do that. But size of input is not frozen. We need smallvec-like array.

@xtqqczze

Copy link
Copy Markdown
Collaborator

We need smallvec-like array.

Issue opened: #16380.

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.

4 participants