NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.65k stars 13.8k forks source link

Python wrapper bash script does quadratic string append #145131

Open nh2 opened 2 years ago

nh2 commented 2 years ago

Similar to other quadratic shell behaviour that massively slowed down package builds: #27609

https://github.com/NixOS/nixpkgs/blob/25e6a0ad62ee9bba99bbc7d9dee174d265cf91fc/pkgs/development/interpreters/python/setup-hook.sh#L7-L10

It would make sense to make this non-quadratic.

CC @FRidh, and @orivej who fixed it for #27609 in e.g. commit 4964b104b946e889587407e27fa11f9412e24c8b

l0b0 commented 2 years ago

The original implementation only cares about $1, so all the call sites which use toPythonPath $out or similar won't work with more than one path. This is probably a bug, right?

Given that, would you be OK with a solution like this one?

toPythonPath() {
    printf '%s/@sitePackages@' "$1"
    shift
    printf ':%s/@sitePackages@' "$@"
    printf '\n' # This line is technically unnecessary, and could be removed
}