summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorSean Kurtz <seankurtz75@gmail.com>2026-11-25 17:50:59 -0600
committerSean Kurtz <seankurtz75@gmail.com>2026-11-25 17:50:59 -0600
commit4eba9006c8f36164070690e34e9be10f94d39221 (patch)
treefe95f9118c77b38fc06c5ebcc49cd7e1d2dda2cc /src
parent0ebef9da03f1952e8d0189a48cd7b946a7369f4f (diff)
downloadzash-perf/fork-fastpath.tar.gz
perf: temporary fork-path ablation switchesperf/fork-fastpath
Diffstat (limited to 'src')
-rw-r--r--src/exec.c23
-rw-r--r--src/exec.h1
-rw-r--r--src/main.c7
3 files changed, 26 insertions, 5 deletions
diff --git a/src/exec.c b/src/exec.c
index c0267a8..c227171 100644
--- a/src/exec.c
+++ b/src/exec.c
@@ -511,6 +511,18 @@ void unwind_restore(const unwind *u) {
/* ---- processes ------------------------------------------------------- */
/**
+ * @brief Temporary experiment: bit mask of fork-path steps to skip.
+ */
+int perf_ablate(void) {
+ static int bits = -1;
+ if (bits < 0) {
+ const char *s = getenv("ZASH_FORK_ABLATE");
+ bits = s ? atoi(s) : 0;
+ }
+ return bits;
+}
+
+/**
* @brief fork() a copy of the shell.
*
* The child is a subshell: it forgets the parent's jobs and traps, and
@@ -520,7 +532,8 @@ void unwind_restore(const unwind *u) {
* raises an error.
*/
pid_t fork_shell(void) {
- flush_all();
+ if (!(perf_ablate() & 4))
+ flush_all();
(void)shell_pid(); /* fix $$ before the pid changes */
pid_t pid = fork();
if (pid < 0)
@@ -530,8 +543,10 @@ pid_t fork_shell(void) {
stat_spawns = stat_forks = 0;
if (job_launching)
job_child_setup(); /* while SIGTTOU is still ignored */
- jobs_forget();
- trap_reset_child();
+ if (!(perf_ablate() & 1))
+ jobs_forget();
+ if (!(perf_ablate() & 2))
+ trap_reset_child();
} else {
stat_forks++;
if (job_launching)
@@ -544,6 +559,8 @@ pid_t fork_shell(void) {
* @brief Run a command as the whole remaining life of this (forked) process.
*/
[[noreturn]] static void child_eval(node *n) {
+ if (perf_ablate() & 8)
+ _exit(0);
jmploc jl;
if (setjmp(jl.buf) == 0) {
exc_handler = &jl;
diff --git a/src/exec.h b/src/exec.h
index 54f5b3e..b278ee0 100644
--- a/src/exec.h
+++ b/src/exec.h
@@ -109,6 +109,7 @@ enum {
};
void find_command(const char *name, cmdinfo *ci, unsigned flags);
+int perf_ablate(void);
void func_define(const char *name, node *body, arena *owner);
bool func_unset(const char *name);
void func_each(void (*fn)(const char *name, void *arg), void *arg);
diff --git a/src/main.c b/src/main.c
index 43026f6..7821ec3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -280,7 +280,9 @@ void exit_shell(int status) {
exiting = true;
exitstatus = status;
jmploc jl;
- if (setjmp(jl.buf) == 0) {
+ if (perf_ablate() & 16) {
+ /* experiment: skip the EXIT trap */
+ } else if (setjmp(jl.buf) == 0) {
exc_handler = &jl;
trap_run_exit();
} else if (exc_code == EXC_EXIT) {
@@ -295,7 +297,8 @@ void exit_shell(int status) {
if (!in_subshell && var_get("ZASH_PROCSTAT"))
out_printf(&out2, "zash: spawns=%ld forks=%ld\n", stat_spawns,
stat_forks);
- flush_all();
+ if (!(perf_ablate() & 32))
+ flush_all();
_exit(code);
}