Skip to content

Conversation

@Radvendii
Copy link
Contributor

@Radvendii Radvendii commented Sep 22, 2025

Motivation

Separate the concerns of memory management from the rest of EvalState. This will become even more important in the future as we take on more management of the heap.

Context

Co-authored-by: eldritch horrors [email protected]
https://git.lix.systems/lix-project/lix/commit/f5754dc90ae9b1207656d0e29ad2704d3ef1e554


Add 👍 to pull requests you find important.

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

CC @xokdvium

@github-actions github-actions bot added new-cli Relating to the "nix" command repl The Read Eval Print Loop, "nix repl" command and debugger c api Nix as a C library with a stable interface labels Sep 22, 2025
@Radvendii Radvendii force-pushed the eval-memory branch 3 times, most recently from 3ca0525 to f124072 Compare September 22, 2025 18:59
@xokdvium xokdvium force-pushed the eval-memory branch 2 times, most recently from 9f6202e to efe955f Compare September 22, 2025 19:50
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.

Fixed some outstanding issues with baseEnvP (bad merge probably). Let's wait for @roberth to take a look as well.

Copy link
Member

@edolstra edolstra left a comment

Choose a reason for hiding this comment

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

Can you explain a bit more about the context? What does "take on more management of the heap" mean?

Changing all these state.allocValue() to state.mem.allocValue() seems like gratuitous code churn to me that will cause a lot of merge conflicts.

@Mic92
Copy link
Member

Mic92 commented Sep 23, 2025

Can you explain a bit more about the context? What does "take on more management of the heap" mean?

Different gc implementations, @Radvendii in particular is working on using 32bit indices rather than pointers to reduce memory usage. This would require a new gc however. I also experimented with bumper allocators for nix-eval-jobs.

Changing all these state.allocValue() to state.mem.allocValue() seems like gratuitous code churn to me that will cause a lot of merge conflicts.

Which pull requests do you have in mind? I don't see too much regarding evaluation at the moment.

Note that he ported this patch based on @xokdvium request, discussed during a team meeting.

@Ericson2314
Copy link
Member

I was not paying super close attention, but @roberth and @xokdvium I believe also discussed how the evaluator would become a bit more opaque in order to support @roberth's eval cahing work. I think moving the things to mem was supposed to be a precursor for that.

@edolstra
Copy link
Member

more opaque in order to support @roberth's eval cahing work

That may be premature abstraction though if we don't know what @roberth's eval caching work will require from a memory interface.

@Radvendii in particular is working on using 32bit indices rather than pointers to reduce memory usage.

That sounds great, but unless we anticipate that we would have multiple implementations in the same code base (rather than just replacing the existing one), having an extra abstraction layer may just make such work harder rather than easier.

BTW, one way to reduce the code churn in this PR a lot is to keep EvalState::allocValue() as an inline forwarder to mem.allocValue().

@xokdvium
Copy link
Contributor

EvalState::allocValue() as an inline forwarder to mem.allocValue().

This sounds good.

@Ericson2314
Copy link
Member

EvalState::allocValue() as an inline forwarder to mem.allocValue()

OK great, if we can unblock this by doing that to make the new mem field low-cost code churn wise, that's great!

@roberth
Copy link
Member

roberth commented Sep 24, 2025

more opaque in order to support @roberth's eval cahing work

That may be premature abstraction though if we don't know what @roberth's eval caching work will require from a memory interface.

I plan to add a layer that goes around the "outside" of the evaluator, where EvalState is one of the implementations, as well as capturing "IO" like all SourceAccessors and IFD.
I don't think that work is affected by this change.

@Radvendii
Copy link
Contributor Author

Radvendii commented Sep 25, 2025

Okay, I restored EvalState::allocValue() and it just calls EvalMemory::allocValue().

For the record while learning my way around the code base recently I found the number of functions that just forward to another function somewhat confusing. Asking myself things like Why are they there? Am I missing something? Which one should I be using?

I added a comment to make it hopefully clearer.

@Radvendii Radvendii force-pushed the eval-memory branch 2 times, most recently from ac59260 to e90f6de Compare September 25, 2025 17:26
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.

Diff is much smaller

@Radvendii Radvendii mentioned this pull request Sep 26, 2025
41 tasks
: size(size)
, elems(size <= 2 ? inlineElems : (Value **) allocBytes(size * sizeof(Value *)))
{
state.nrListElems += size;
Copy link
Member

@Ericson2314 Ericson2314 Sep 26, 2025

Choose a reason for hiding this comment

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

I am not sure that every ListBuilder is going through the new mem.listBuilder?

OK nevermind, I thought there was some sort of default arg but there is not. This is easy to verify.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I search the codebase, I don't find any other instances. Neither with LSP goto-references nor with a text search for ListBuilder. But it could be getting initialized in some way that is tripping up both searches.

@Mic92 Mic92 dismissed edolstra’s stale review September 26, 2025 17:22

code churn got removed.

@Mic92 Mic92 merged commit b5f765b into NixOS:master Sep 26, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c api Nix as a C library with a stable interface new-cli Relating to the "nix" command repl The Read Eval Print Loop, "nix repl" command and debugger

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants