Skip to content

fileset.fileFilter: Don't run predicate unnecessarily#267381

Merged
infinisil merged 2 commits intoNixOS:masterfrom
tweag:fileset.fileFilter-path
Nov 15, 2023
Merged

fileset.fileFilter: Don't run predicate unnecessarily#267381
infinisil merged 2 commits intoNixOS:masterfrom
tweag:fileset.fileFilter-path

Conversation

@infinisil
Copy link
Member

@infinisil infinisil commented Nov 14, 2023

Description of changes

Before:

nix-repl> :a lib.fileset

nix-repl> trace (fileFilter (file: builtins.trace file.name false) ./default.nix)
trace: README.md
trace: benchmark.sh
trace: default.nix
trace: internal.nix
trace: mock-splitRoot.nix
trace: tests.sh

After:

nix-repl> trace (fileFilter (file: builtins.trace file.name false) ./default.nix)
trace: default.nix

Note that even if the filter returned true before, the files weren't added to the store, so this is just a performance and laziness improvement and arguably not a bug fix.

This work is sponsored by Antithesis

Things done

  • Cleaned up surrounding code
  • Added tests

Before:

    nix-repl> fileset.trace (fileset.fileFilter (file: builtins.trace file.name false) ./default.nix)
    trace: README.md
    trace: benchmark.sh
    trace: default.nix
    trace: internal.nix
    trace: mock-splitRoot.nix
    trace: tests.sh

After:

    nix-repl> fileset.trace (fileset.fileFilter (file: builtins.trace file.name false) ./default.nix)
    trace: default.nix
@github-actions github-actions bot added the 6.topic: lib The Nixpkgs function library label Nov 14, 2023
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Nov 14, 2023
@infinisil infinisil merged commit 7e533ba into NixOS:master Nov 15, 2023
@infinisil infinisil deleted the fileset.fileFilter-path branch November 15, 2023 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: lib The Nixpkgs function library 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant