Previously nixVersions.latest.tests.nixpkgs-lib was testing the stable version,
which we definitely don't expect. Since test-with-nix.nix is also used by lix
it meant that it didn't actually run lib.path tests at all.
If we don't do this, we end up with an annoying malformed generated.json
and have to revert it somehow. Easy, but annoying, so let's just pay
attention to error codes and commit only when it's succeeded.
Wins vs. parent:
- 71k fewer thunks
- 41k fewer lookups
I think this is safe. It's slightly less lazy. I couldn't come up with a
case that it breaks, though.
Every declaration copied `module._file` with a select, which costs a
thunk per declared option. If instead we destructure the module,
we bind `_file` and `options` once, and the declarations can refer
to them directly.
Wins vs. parent:
- 35k fewer envs
- 91k fewer thunks
- 35k fewer lookups
Module configs passed to mergeModules' were `{ file, config }`, while
the definitions they are split into are `{ file, value }`.
Wins vs. parent:
- 14k fewer thunks
- 10k fewer attrsets
- 552 KiB saved in attrset bytes
Since imap1 is itself implemented with genList, calling genList directly
saves a function call per module.
Wins vs. parent:
- 59k fewer envs
- 12k fewer thunks
- 59k fewer function calls
And no regressions. A win.
Most definitions carry no property to push down, so check for `_type`
first and only map over pushDownProperties when there is one.
Modules (`_file`, `config`) and definitions (`file`, `value`) spell
their attributes differently, so each call site destructures its own.
Wins vs. parent:
- 59k fewer envs
- 122k fewer thunks
- 59k fewer function calls
- 29k fewer primops
We don't need to iterate a second time; we can check that each config
is an attribute set **while** building rawDefinitionsByName.
That check runs at every level, including the root, so the duplicate
root-level check in mergeModules can go too. This also restores the
check for direct callers of mergeModules'.
The pushed-down definitions are only needed when descending into a name,
so build them right there, and only if that name has any definitions.
The wins here vs. last commit on that minimal NixOS config:
- 9k fewer envs
- 40k fewer thunks
- 9k fewer function calls
- 41k fewer primop calls
- 11k fewer attrsets
- 600 KiB saved in attrset bytes
Pareto improvement.
The idea here is that, to construct unmatchedDefns, we use a combo of mapAttrs and mapAttrsToList over every name at every level.
But notice: almost all of those names are options with no unmatched definitions!
So, instead of doing that, we can have nested results prefix their own unmatched definitions, so the parent can concatenate them with catAttrs.
The wins here vs. last commit on that minimal NixOS config:
- 188k fewer envs
- 201k fewer function calls
- 7k fewer primop calls
- 7k fewer attrsets
- 1.4 MiB saved in attrset bytes
There are 3k more thunks, but we'll make that up with the next patches.
It's a truism that almost every option is declared exactly once.
For those singletons, mergeModules' went through mergeOptionDecls,
fixupOptionType and evalOptionValue, each of which builds a new attrset
from the previous one.
If we instead check the declaration's `_type` inline and build
the evaluated option (as in, its declaration and value attributes)
in a single attribute set update, it's a lot cheaper.
It comes at the cost of repeating evalOptionValue's attribute list,
so the two need to be marked to be kept in sync.
Since mergeOptionDecls is now never called with a single declaration
from within Nixpkgs (types.optionType already short-circuits that case),
we can then drop its single-declaration special case.
Now that fixupOptionType is idempotent, mergeOptionDecls can apply it
itself, resolving the TODO. Every caller already followed one with the
other, and callers outside Nixpkgs that still do are unaffected.
I really hate this duplication, but it does save (vs. parent)
a *lot* on the minimal NixOS config cited in the comments.
- 164k envs
- 51k thunks
- 140k function calls
- 52k attrsets
- 570 KiB in attrset bytes
There is a gratuitous capitalization and reflowing of a comment in this
patch. Sorry, I like to do that.
fixupOptionType substitutes the submodules collected in `options` into
the option's type, then clears `options`. Applied a second time, it
substituted that empty list, dropping every submodule from the type.
With no submodules left to substitute, there is nothing to fix up, so
return the option as-is. This lets mergeOptionDecls do the fixup itself
without breaking callers that still call fixupOptionType afterwards.
Previously, we would always call `pushDownProperties` recursively - but
now we only do it if the second layer also needs to be pushed. Saves a
`map` and a function call on each definition.
Inline the bothHave closure into 4 direct checks, and bind opt.options
once instead of reselecting it 8 times per fold step.
Measured on a real NixOS+Plasma eval, output byte-identical:
nrFunctionCalls -2.35%, Envs -1.98% (-1.58% bytes), cpuTime -3.53%,
GC totalBytes -0.27%.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Assisted-by: Claude Sonnet 5 <noreply@anthropic.com>