Skip to content

Commit 49e7a6b

Browse files
danielzgtgsylvestre
authored andcommitted
perf(uucore): call rt_sigaction once not 62 times
`./coreutils true` becomes 6% faster. For some unknown reason, `capture_startup_state` runs 62 times, so I'll just hotfix it to immediately return from the second time onwards. When 2d7a3bf introduced the fcntl calls, each group of 3 calls was repeated 4 times. Some time later, it became 62 times. Now it runs only 1 time.
1 parent 0260f21 commit 49e7a6b

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/uucore/src/lib/features/signals.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,9 @@ static STDERR_WAS_CLOSED: AtomicBool = AtomicBool::new(false);
538538
#[cfg(unix)]
539539
static SIGPIPE_WAS_IGNORED: AtomicBool = AtomicBool::new(false);
540540

541+
#[cfg(unix)]
542+
static STARTUP_STATE_WAS_CAPTURED: AtomicBool = AtomicBool::new(false);
543+
541544
/// Captures stdio and SIGPIPE state at process initialization, before main() runs.
542545
///
543546
/// # Safety
@@ -549,6 +552,11 @@ pub unsafe extern "C" fn capture_startup_state() {
549552
use std::mem::MaybeUninit;
550553
use std::ptr;
551554

555+
// No spinlock because we're single-threaded at this point
556+
if STARTUP_STATE_WAS_CAPTURED.swap(true, Ordering::Relaxed) {
557+
return;
558+
}
559+
552560
// Capture stdio state
553561
unsafe {
554562
STDIN_WAS_CLOSED.store(

0 commit comments

Comments
 (0)