Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xspawn: Wrap the real posix_spawn() if possible #127

Merged
merged 6 commits into from
Nov 6, 2023
Merged

Conversation

tavianator
Copy link
Owner

@tavianator tavianator commented Nov 2, 2023

Benchmark results

Process spawning

linux v6.5

One file per process

Command Mean [s] Min [s] Max [s] Relative
bfs bench/corpus/linux -maxdepth 2 -exec true -- {} \; 1.385 ± 0.012 1.364 1.398 4.07 ± 0.18
bfs-main bench/corpus/linux -maxdepth 2 -exec true -- {} \; 1.578 ± 0.013 1.556 1.602 4.64 ± 0.21
bfs-posix-spawn bench/corpus/linux -maxdepth 2 -exec true -- {} \; 1.150 ± 0.011 1.124 1.164 3.38 ± 0.15
find bench/corpus/linux -maxdepth 2 -exec true -- {} \; 1.475 ± 0.019 1.446 1.496 4.33 ± 0.20
fd -u --search-path bench/corpus/linux --max-depth=2 -x true -- 0.340 ± 0.015 0.316 0.365 1.00
fd -j1 -u --search-path bench/corpus/linux --max-depth=2 -x true -- 1.142 ± 0.021 1.110 1.165 3.36 ± 0.16

Many files per process

Command Mean [ms] Min [ms] Max [ms] Relative
bfs bench/corpus/linux -exec true -- {} + 71.8 ± 2.1 66.3 76.1 1.00
bfs-main bench/corpus/linux -exec true -- {} + 73.2 ± 1.3 69.6 75.7 1.02 ± 0.03
bfs-posix-spawn bench/corpus/linux -exec true -- {} + 157.8 ± 2.0 154.0 161.8 2.20 ± 0.07
find bench/corpus/linux -exec true -- {} + 262.3 ± 2.4 260.0 268.6 3.65 ± 0.11
fd -u --search-path bench/corpus/linux -X true -- 314.4 ± 5.5 305.7 321.3 4.38 ± 0.15

Spawn in parent directory

Command Mean [ms] Min [ms] Max [ms] Relative
bfs bench/corpus/linux -maxdepth 3 -execdir true -- {} + 844.1 ± 9.4 833.9 865.1 1.75 ± 0.04
bfs-main bench/corpus/linux -maxdepth 3 -execdir true -- {} + 913.2 ± 19.4 873.8 951.0 1.89 ± 0.05
bfs-posix-spawn bench/corpus/linux -maxdepth 3 -execdir true -- {} + 483.5 ± 9.1 467.8 500.8 1.00
find bench/corpus/linux -maxdepth 3 -execdir true -- {} + 1115.6 ± 17.9 1091.0 1151.1 2.31 ± 0.06

Details

Versions

$ bfs --version | head -n1
bfs 3.0.4
$ bfs-main --version | head -n1
bfs 3.0.4-43-gb2ab7a15
$ bfs-posix-spawn --version | head -n1
bfs 3.0.4-49-g7d69fef6
$ find --version | head -n1
find (GNU findutils) 4.9.0
$ fd --version
fd 8.7.1

Copy link

codecov bot commented Nov 2, 2023

Codecov Report

Attention: 53 lines in your changes are missing coverage. Please review.

Files Coverage Δ
src/ctx.c 81.39% <50.00%> (-0.15%) ⬇️
src/eval.c 72.16% <92.85%> (+0.61%) ⬆️
src/bfstd.c 74.60% <64.28%> (-4.28%) ⬇️
src/exec.c 72.55% <70.00%> (-0.30%) ⬇️
src/xspawn.c 20.96% <36.50%> (-37.64%) ⬇️

... and 2 files with indirect coverage changes

📢 Thoughts on this report? Let us know!.

src/xspawn.c Fixed Show fixed Hide fixed
@tavianator
Copy link
Owner Author

There is a surprising perf regression for -exec ... {} +, but IMO the benefits outweigh it. It seems like either the kernel or glibc's fault anyway, and ought to be fixed there.

This also works around google/sanitizers#1699. Hopefully no more CI timeouts!

@tavianator tavianator merged commit 7d69fef into main Nov 6, 2023
@tavianator tavianator deleted the posix-spawn branch November 6, 2023 15:31
tavianator added a commit that referenced this pull request Nov 7, 2023
posix_spawnp() is typically implemented like execvp(), i.e., by
repeatedly trying execv() with each $PATH component until it succeeds.
This is much slower than resolving the executable path up-front and then
calling execv() once, so do that.

Fixes: #127 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant