Skip to content

Conversation

Radvendii
Copy link
Contributor

@Radvendii Radvendii commented Oct 5, 2025

Motivation

Waste of 4 bytes (per attr definition, and there are a lot of attr definitions). It's just the offset into the std::map, and can be calculated where it's needed using std::distance().

I also reordered the remaining fields to avoid padding

Saves ~1% memory (~10MB)

Additional benefits:

  • having a counter that just keeps track of your position in an iterator that is right there seems error-prone to me.
  • This removes the need for AttrDefs to be mutable after parsing, which is useful for reworking ExprAttrs

Context


Add 👍 to pull requests you find important.

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

CC @xokdvium @NaN-git

Waste of 4 bytes; it can be calculated where it's needed.

I also reordered the remaining fields to avoid padding
@Radvendii Radvendii requested a review from edolstra as a code owner October 5, 2025 22:25
Hence we need __overrides.) */
if (hasOverrides) {
Value * vOverrides = (*bindings.bindings)[overrides->second.displ].value;
Value * vOverrides = (*bindings.bindings)[std::distance(attrs.begin(), overrides)].value;
Copy link
Contributor

Choose a reason for hiding this comment

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

Accidental complexity jump here. Also can we add a bit more tests for __overrides feature?

@edolstra
Copy link
Member

edolstra commented Oct 6, 2025

Isn't std::distance on a map much slower (since it needs to iterate until it find the key)?

@Radvendii
Copy link
Contributor Author

You're both right. I didn't realize that's how std::map was implemented. With my next change, this will be O(1), so we can wait until I've finished that.

@Radvendii Radvendii closed this Oct 6, 2025
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