Skip to content

posix_spawn: Unconditionally default all signals (except HUP)#10869

Merged
faho merged 1 commit into
fish-shell:masterfrom
faho:spawn-default-all-sigs
Nov 30, 2024
Merged

posix_spawn: Unconditionally default all signals (except HUP)#10869
faho merged 1 commit into
fish-shell:masterfrom
faho:spawn-default-all-sigs

Conversation

@faho
Copy link
Copy Markdown
Member

@faho faho commented Nov 25, 2024

As I understand it, we want all signals for processes we spawn (except for HUP, because of nohup) to have the default signal handlers.

So I don't know why we need to check what action a specific signal currently has, we can just default it anyway.

This saves ~30 syscalls per process we spawn, so:

for f in (seq 1000)
    command true
end

has ~30000 fewer rt_sigaction calls. These take up about ~30% of the total time spent in syscalls according to strace.

We could also compute this set once at startup and then reuse it.

We don't really care if the process has a custom handler installed, we
can just set it to default.

The one we check is SIGHUP, which may be given to us via `nohup`.

This saves ~30 syscalls *per process* we spawn, so:

```fish
for f in (seq 1000)
    command true
end
```

has ~30000 fewer rt_sigaction calls. These take up about ~30% of the
total time spent in syscalls according to strace.

We could also compute this set once at startup and then reuse it.
@faho faho added this to the fish 4.0 milestone Nov 25, 2024
@faho faho requested a review from ridiculousfish November 25, 2024 15:57
Copy link
Copy Markdown
Member

@ridiculousfish ridiculousfish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great find! I can't think of any reason to not do this.

@faho faho added the performance Purely performance-related enhancement without any changes in black box output label Nov 30, 2024
@faho faho merged commit 4859606 into fish-shell:master Nov 30, 2024
@faho faho deleted the spawn-default-all-sigs branch November 30, 2024 22:00
@krobelus
Copy link
Copy Markdown
Contributor

krobelus commented Dec 4, 2024

We could also compute this set once at startup and then reuse it.

yeah we can cache these indefinitely, other shells do that too

faho added a commit that referenced this pull request Dec 4, 2024
Really the only thing we're looking for here is if we're started with
HUP ignored or not.

Saves a syscall per external process.

Continuation of #10869
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Dec 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement performance Purely performance-related enhancement without any changes in black box output

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants