File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ pub(super) fn write_fast_using_splice<R: FdReadable, S: AsRawFd + AsFd + Write>(
2121 handle : & InputHandle < R > ,
2222 write_fd : & mut S ,
2323) -> CatResult < bool > {
24+ use std:: { fs:: File , sync:: OnceLock } ;
25+ static PIPE_CACHE : OnceLock < Option < ( File , File ) > > = OnceLock :: new ( ) ;
2426 if splice ( & handle. reader , & write_fd, MAX_ROOTLESS_PIPE_SIZE ) . is_ok ( ) {
2527 // fcntl improves throughput
2628 // 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<R: FdReadable, S: AsRawFd + AsFd + Write>(
3234 Err ( _) => return Ok ( true ) ,
3335 }
3436 }
35- } else if let Ok ( ( pipe_rd, pipe_wr) ) = pipe ( ) {
37+ } else if let Some ( ( pipe_rd, pipe_wr) ) = PIPE_CACHE . get_or_init ( || pipe ( ) . ok ( ) ) . as_ref ( ) {
3638 // both of in/output are not pipe. needs broker to use splice() with additional costs
3739 loop {
3840 match splice ( & handle. reader , & pipe_wr, MAX_ROOTLESS_PIPE_SIZE ) {
You can’t perform that action at this time.
0 commit comments