From dc18b54fb7b588e2d41e35bdd694454a0dcdd04c Mon Sep 17 00:00:00 2001 From: oech3 <79379754+oech3@users.noreply.github.com> Date: Tue, 21 Apr 2026 05:36:15 +0900 Subject: [PATCH] cat: call pipe() once with multiple input (#11699) --- src/uu/cat/src/splice.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/uu/cat/src/splice.rs b/src/uu/cat/src/splice.rs index f9082ff26..8096166f0 100644 --- a/src/uu/cat/src/splice.rs +++ b/src/uu/cat/src/splice.rs @@ -21,6 +21,8 @@ pub(super) fn write_fast_using_splice( handle: &InputHandle, write_fd: &mut S, ) -> CatResult { + use std::{fs::File, sync::OnceLock}; + static PIPE_CACHE: OnceLock> = OnceLock::new(); if splice(&handle.reader, &write_fd, MAX_ROOTLESS_PIPE_SIZE).is_ok() { // fcntl improves throughput // todo: avoid fcntl overhead for small input, but don't fcntl inside of the loop @@ -32,7 +34,7 @@ pub(super) fn write_fast_using_splice( Err(_) => return Ok(true), } } - } else if let Ok((pipe_rd, pipe_wr)) = pipe() { + } else if let Some((pipe_rd, pipe_wr)) = PIPE_CACHE.get_or_init(|| pipe().ok()).as_ref() { // both of in/output are not pipe. needs broker to use splice() with additional costs loop { match splice(&handle.reader, &pipe_wr, MAX_ROOTLESS_PIPE_SIZE) {