From 1c110552413fce035c94e80ace5bfa4e9f216535 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Thu, 16 Jan 2025 19:32:15 +0100 Subject: [PATCH] Don't clone argv for builtins We capture the process already, and we use argv by reference for the other cases. argv can be big, and this reduces allocations and thereby memory usage and speed. E.g. `set -l foo **` with 200k matches has 25% reduced memory usage and ~5% reduced runtime. --- src/exec.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/exec.rs b/src/exec.rs index 0d8362498..0b9e9b7ba 100644 --- a/src/exec.rs +++ b/src/exec.rs @@ -1106,7 +1106,6 @@ fn get_performer_for_builtin(p: &Process, j: &Job, io_chain: &IoChain) -> Box Box, errput_stream: Option<&mut OutputStream>| { let output_stream = output_stream.unwrap(); @@ -1151,8 +1150,11 @@ fn get_performer_for_builtin(p: &Process, j: &Job, io_chain: &IoChain) -> Box = - argv.iter().map(|s| truncate_at_nul(s.as_ref())).collect(); + let mut shim_argv: Vec<&wstr> = p + .argv() + .iter() + .map(|s| truncate_at_nul(s.as_ref())) + .collect(); builtin_run(parser, &mut shim_argv, &mut streams) }, )