libexpr: Add filterAttrs builtin#14753
Closed
not-ronjinger wants to merge 2 commits intoNixOS:masterfrom
Closed
Conversation
Contributor
|
This user was banned. |
crertel
added a commit
to crertel/nix
that referenced
this pull request
Dec 11, 2025
|
Is it possible to reopen this after NixOS/org#229 got merged? |
Contributor
|
I do want |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The implementation in nixpkgs is slightly inefficient:
Namely, it has to create a temporary list of names
attrNames set, then has to scan through the entries withfilter, apply the predicate which needs to dereference the value, then pass it toremoveAttrs, which then needs to do another scan of names which failed the predicate. It's likely as good as you can get without creating a specific builtin.With a native builtin, we should be able to eliminate the need for generating the temporary list, the initial scan should be a bit faster as there is less indirection with looking up the value, and the need to do another scan for removeAttrs should be eliminated altogether.
Re-introducing this to nixpkgs/lib should be easy with a
builtins ? filterAttrscheck.Context
Gotta go fast 🚀