Skip to content

Commit

Permalink
perf(exec): improve performance
Browse files Browse the repository at this point in the history
...by only parsing installed packages for their environment variables if
we are in a deactivated hermit environment. When activated, the parent
shell will have already passed the new process all environment
variables, including packages that were installed after initial
activation. Parsing the HCL configs of all installed packages introduces
some overhead. This can be non-negligible when hermit-managed
packages are used a large number of times - for instance with javac or
rustc.
  • Loading branch information
nickajacks1 committed Feb 9, 2025
1 parent a40f20c commit 606108b
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions env.go
Original file line number Diff line number Diff line change
Expand Up @@ -783,10 +783,21 @@ func (e *Env) Exec(l *ui.UI, pkg *manifest.Package, binary string, args []string
return errors.WithStack(err)
}

installed, err := e.ListInstalled(l)
if err != nil {
return errors.WithStack(err)
var installed []*manifest.Package

// If we are activated, the parent shell already has
// already passed us all necessary environment variables.
// This may not be the case if the user manually ran
// e.g. ./bin/go
// We still need to call e.allEnvarOpsForPackages to ensure
// the selected package's env vars take precedence.
if os.Getenv("DEACTIVATED_HERMIT") != "" {
installed, err = e.ListInstalled(l)
if err != nil {
return errors.WithStack(err)
}
}

ops := e.allEnvarOpsForPackages(runtimeDeps, pkg, installed...)
packageHermitBin, err := e.getPackageRuntimeEnvops(pkg)
if err != nil {
Expand All @@ -797,9 +808,6 @@ func (e *Env) Exec(l *ui.UI, pkg *manifest.Package, binary string, args []string
}
env := e.envarsFromOps(true, ops)

if err != nil {
return errors.WithStack(err)
}
for _, bin := range binaries {
if filepath.Base(bin) != filepath.Base(binary) {
continue
Expand Down

0 comments on commit 606108b

Please sign in to comment.