Repository navigation
perf: break closure chains and lazy instantiation backport - #579
Merged
Merged
Conversation
Collaborator
Author
|
This is a subset backport of the enhancements I've made on the gen-schema branch while migrating my personal nix-config over. |
sini
force-pushed
the
perf/closure-chain-breakup
branch
from
May 30, 2026 20:31
8f438f4 to
7c99e12
Compare
Backport perf and fix commits from the den-lazy branch that are independent of the gen-schema migration work. Perf — closure chain elimination: State helpers (scopedAppend/scopedMerge/etc.) stored accumulated state behind `_: ...` thunks. Each write wrapped the previous thunk, creating a closure chain of depth N. Reading the final value cost O(N), and ~2,900 reads gave O(N²) total. Fix: materialise the previous state eagerly outside the thunk. Cold eval: -17%, memory: -70%, attrset copies: -88%. Perf — lazy instantiation: applyInstantiates and hostConfigs now defer spec.instantiate behind thunks so hosts are only evaluated when accessed. Fixes: - safe fallback when entity kind has no aspect defined - default path=[] in policy.route constructor - skip unsatisfied parametric pipe values in resolveLocalParametric Feature: - pipe.collectAll — collects from all scopes matching a predicate
sini
force-pushed
the
perf/closure-chain-breakup
branch
from
May 31, 2026 15:50
7c99e12 to
4399b7a
Compare
theutz
enabled auto-merge (squash)
May 31, 2026 23:32
theutz
approved these changes
May 31, 2026
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.
Summary
Backport of perf and fix commits from the den-lazy branch, independent of the gen-schema migration.
Performance
scopedAppend/scopedMerge/etc.) stored accumulated state behind_: ...thunks, creating O(N) closure chains. N reads = O(N²). Fix: materialise the previous state eagerly outside the thunk. Cold eval: -17%, memory: -70%, attrset copies: -88%.applyInstantiatesandhostConfigsnow deferspec.instantiatebehind thunks so hosts are only evaluated when accessed. Eliminates unnecessary NixOS config evaluation for multi-host flakes.Fixes
path=[]inpolicy.routeconstructorresolveLocalParametricFeature
pipe.collectAll— collects from all scopes matching a predicateMotivation
The closure chain fix directly resolves stack overflow in nix-unit sandbox evaluation for configs with deep NixOS module trees (e.g. configs using stylix + plasma-manager + sops-nix). Verified against a users config where
nix flake checkwas failing with stack overflow.Test plan
nix flake checkpasses on oceangreendev config (previously stack overflow)