Skip to content

An idea to speed up stubs #1136

@felipecrs

Description

@felipecrs

Hi, I was doing some experiments, and I was able to speed up stubs by around 10%.

However, to make it work for real it will require a new flag or environment variable in pkgx, like --swallow-first-arg or PKGX_SWALLOW_FIRST_ARG=1.

The idea is simple: instead of relying on sh to run pkgx, use just env instead:

cat ./test-sh
#!/usr/bin/env sh

exec pkgx echo "$0" "$@"cat ./test-env
#!/usr/bin/env -S pkgx echo

Benchmarks:

pkgx hyperfine --warmup 2 --shell none --runs 1000 './test-sh' './test-env'
Benchmark 1: ./test-sh
  Time (mean ± σ):       7.1 ms ±   0.5 ms    [User: 3.9 ms, System: 4.1 ms]
  Range (min … max):     6.5 ms …  15.1 ms    1000 runs

Benchmark 2: ./test-env
  Time (mean ± σ):       6.5 ms ±   0.2 ms    [User: 3.9 ms, System: 3.5 ms]
  Range (min … max):     5.9 ms …   8.0 ms    1000 runs

Summary
  ./test-env ran
    1.09 ± 0.09 times faster than ./test-sh

But once the flag is implemented, then the stubs can look like:

#!/usr/bin/env -S pkgx --swallow-first-arg echo

Or something shorter like pkgx -# echo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions