Skip to content

libexpr: don't allocate additional set in builtins.listToAttrs #13387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2025

Conversation

NaN-git
Copy link
Contributor

@NaN-git NaN-git commented Jun 22, 2025

Motivation

At the moment this function uses an additional std::set to filter duplicate keys. This causes many additional allocations for the nodes in the set.
Finally the Bindings are sorted, although the set contains the keys in sorted order already.

Context

The additional std::set is not necessary. Instead the Bindings are sorted and filtered in a single array.


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@NaN-git NaN-git requested a review from roberth as a code owner June 22, 2025 17:15
Copy link
Contributor

@xokdvium xokdvium left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimization LGTM. It's a bit hacky, since it slightly abuses the fact Bindings::operator[] does not check that the access isn't out of bounds of size_. In the future we might want a cleaner API for doing such optimizations.

@NaN-git
Copy link
Contributor Author

NaN-git commented Jun 29, 2025

Optimization LGTM. It's a bit hacky, since it slightly abuses the fact Bindings::operator[] does not check that the access isn't out of bounds of size_. In the future we might want a cleaner API for doing such optimizations.

In C++ the expectation is that operator[] doesn't do any bounds checks. The convention is to use at(size_t) instead.

@roberth roberth merged commit 04a731b into NixOS:master Jul 2, 2025
12 checks passed
@roberth
Copy link
Member

roberth commented Jul 2, 2025

Thank you @NaN-git!

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.

3 participants