Skip to content

Performance bottleneck #9

@shajra

Description

@shajra

Hi Nicolas,

For a few years, I've been maintaining my own Direnv script based on ideas from the Nix integration page on the Direnv wiki. In the meantime, the field of projects filling this space expanded a lot (Lorri, Sorri, Nixify, for example). So I took a moment to dive into each to decide if I should continue maintaining my own, or just use something maintained by someone else.

In the process of doing that, I found differences in performance with both Lorri and Sorri. The evaluation time for these were both at times around 2x the speed of just going into a Nix shell directly. That overhead isn't as perceptible with Lorri, because it runs as a background process. But it's a more noticeable hit for Sorri, when first building out an environment.

The slowdown seems to be almost entirely due to slipping in tracing on reading files with overrides. I have a toy Haskell project I was playing around with, and just entering a Nix Shell was taking me ~30 seconds (because of some Haskell.nix-based dependencies). That's pretty bad, but at least I have caching. The first-time hit is kind of annoying, though. And if changing files frequently, this could get pretty annoying. When I switched from lightweight auto-detection (no tracing) to full auto-detection, the only file I picked up for the extra 30 seconds of evaluation was the sources.json file from my usage of Niv (that tool is great, thanks for it). Over a minute of evaluation time is pretty extreme for a toy project (granted, Nix has terrible evaluation times, and Haskell.nix only stresses that).

I don't have a PR, but hopefully I've described the problem clearly enough. But that gets to something else I was hoping to run by you.

In all this exploration, I did end up iterating on my own personal project, and though I originally had no desire to rewrite something someone else has worked on, I think this is what I have ended up doing, just to prove out all the ideas I was thinking should be implemented.

Could you have a look at this project? https://github.com/shajra/direnv-nix-lorelei. I'd really appreciate your feedback. I think it has all the functionality Sorri does. The readme file has a small writeup comparing it with prior art. The idea I wanted to play around with was calling Lorri directly, rather than copying/pasting code from that project. I think I pulled that off okay. Also I rolled in a lot of features from all the other scripts that are out there. I did, though, deviate from your approach of scaffolding projects with a script called from .envrc. My approach to installation/configuration is more along the conventional lines of installing into ~/.config/direnv/lib. I do, though, use Nix to directly tie in all the dependencies needed by the script (so users can have confidence it will work upon installation).

There's so many of these projects out there. I empathize with new users confused by yet-another-option. So if you like what you see with Lorelei, I'm curious if you'd be open to joining forces behind one project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions