Skip to content

builtins.filterAttrs #11888

Open
Open

Description

@roberth

Is your feature request related to a problem? Please describe.

  • lib.filterAttrs allocates a list of attribute names twice.

filterAttrs is called every time attrsOf produces a value, and it needs to, because of mkIf.
Plenty of other usages exist.

Describe the solution you'd like

Add builtins.filterAttrs with the same behavior.

Side benefit: stack traces will be slightly shorter without losing info.

Describe alternatives you've considered

Additional context

Priorities

Add 👍 to issues you find important.

Activity

  1. added
    feature
    error-messages
    language
    on Nov 15, 2024
  2. Pandapip1 commented on May 13, 2026

    @Pandapip1
    Member
  3. roberth commented on May 20, 2026

    @roberth
    MemberAuthor

    This wouldn't be any different from lib.filterAttrs semantically, except slightly faster to execute.

  4. Pandapip1 commented on May 20, 2026

    @Pandapip1
    Member

    This wouldn't be any different from lib.filterAttrs semantically, except slightly faster to execute.

    Wouldn't it be able to avoid instantiating everything in the original attrset (which lib.filerAttrs currently has to do)?

  5. roberth commented on May 20, 2026

    @roberth
    MemberAuthor

    In the current data model, a value changes from thunk to attrset, and any value that's identified as an attrset has a known set of names. This means there's no step in-between where an attrset is usable without knowing all the names.
    As for values, those can all remain unknown, in their thunk state.

    This really constrains what any filterAttrs implementation can do, even here.
    Changing the data model would be a significant change (which has been attempted in #4154, but now highly out of date, and evaluator optimizations since then may have changed the balance)
    Alternatively something along the lines of #8187 could make the concept of an attrset abstract and user-implementable. Given the right proxy interface, a lazier filterAttrs is implementable.

    What I had in mind for this issue is just a faster lib.filterAttrs though. Same for #15100

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    error-messagesfeaturelanguageperformance

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions