Skip to content

database: parallelize queries with independent zstd frames - #325

Open
Mic92 wants to merge 1 commit into
masterfrom
more-perf
Open

database: parallelize queries with independent zstd frames#325
Mic92 wants to merge 1 commit into
masterfrom
more-perf

Conversation

@Mic92

@Mic92 Mic92 commented Jul 2, 2026

Copy link
Copy Markdown
Member

nix-locate decompressed and scanned the whole database in one thread. Because it was a single zstd frame, the work could not be split across cores.

Store the database as independently-compressed zstd frames, cut only at package boundaries so each is a self-contained frcode stream. Frame offsets go in a trailing skippable frame that plain zstd -d ignores. nix-locate then searches all frames in parallel, and nix-index compresses them in parallel.

Version 1 databases are still read, and nix-index --format-version 1 still writes them for consumers that need the legacy format (e.g. nix-index-database).

Benchmark (nix-locate bin/ls, full nixpkgs index, 16 cores, hyperfine):

before:  2.225 s ± 0.041 s
after:   0.690 s ± 0.027 s

nix-locate decompressed and scanned the whole database in one thread.
Because it was a single zstd frame, the work could not be split across
cores.

Store the database as independently-compressed zstd frames, cut only at
package boundaries so each is a self-contained frcode stream. Frame
offsets go in a trailing skippable frame that plain `zstd -d` ignores.
nix-locate then searches all frames in parallel, and nix-index compresses
them in parallel.

Version 1 databases are still read, and `nix-index --format-version 1`
still writes them for consumers that need the legacy format (e.g.
nix-index-database).

Benchmark (`nix-locate bin/ls`, full nixpkgs index, 16 cores, hyperfine):

    before:  2.225 s ± 0.041 s
    after:   0.690 s ± 0.027 s
@Mic92

Mic92 commented Jul 2, 2026

Copy link
Copy Markdown
Member Author

@figsoda

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