lib.options: several small performance cleanups - #517802
Open
llakala wants to merge 8 commits into
Open
Conversation
adisbladis
approved these changes
May 10, 2026
hsjobeki
reviewed
May 10, 2026
hsjobeki
left a comment
Contributor
There was a problem hiding this comment.
lgtm nice improvements overall. Left some nits
| ::: | ||
| */ | ||
| mkEnableOption = | ||
| let |
Contributor
There was a problem hiding this comment.
Not sure if i like the inlining for a performance win of what exactly? Can you measure how much we save here?
dry maintainable code vs inlining for performance reasons is a tradeoff in nix unfortunately.
Contributor
Author
There was a problem hiding this comment.
Sure. With the test case of:
NIX_SHOW_STATS=1 NIX_SHOW_STATS_PATH=after.json \
nix-instantiate -I nixpkgs=. --eval -E '
let nixos = import ./nixos/lib/eval-config.nix {
modules = [ ./nixos/modules/profiles/minimal.nix
{ fileSystems."/" = { device = "/dev/sda1"; fsType = "ext4"; };
boot.loader.grub.devices = ["/dev/sda"]; } ];
}; in nixos.config.system.build.toplevel.drvPath
'Absolute stats diff:
{
"attrset": {
"lookups": -3754,
"merges": -4118,
"mergeCopies": -2059
},
"list": {
"concats": 0
},
"parser": {
"expressions": 2
},
"memory": {
"envs": -197648,
"list": 0,
"sets": -131776,
"symbols": 0,
"values": -65872,
"total": -395296
},
"speed": {
"primops": 0,
"functionCalls": -2059,
"thunksMade": -4117,
"thunksAvoided": -10295
}
}And with percentages enabled:
{
"attrset": {
"lookups": "-0.11%",
"merges": "-0.65%",
"mergeCopies": "-0.04%"
},
"list": {
"concats": null
},
"parser": {
"expressions": "+0%"
},
"memory": {
"envs": "-0.19%",
"list": null,
"sets": "-0.06%",
"symbols": null,
"values": "-0.04%",
"total": "-0.08%"
},
"speed": {
"primops": null,
"functionCalls": "-0.04%",
"thunksMade": "-0.06%",
"thunksAvoided": "-0.18%"
}
}-0.65% merges does seem nice - everything else is rather minor. Up to you.
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.
I'm getting fast at this! Most of these are very small savings, but 0.1% of 4 million function calls is still 4 thousand function calls saved. Hash is the same before/after for both a minimal NixOS config and my own. Stats diff:
{ "attrset": { "lookups": "-0.11%", "merges": "-0.69%", "mergeCopies": "-0.09%" }, "list": { "concats": null }, "parser": { "expressions": null }, "memory": { "envs": "-0.25%", "list": "-0.1%", "sets": "-0.07%", "symbols": null, "values": false, "total": "-0.12%" }, "speed": { "primops": "-0.07%", "functionCalls": "-0.1%", "thunksMade": "-0.1%", "thunksAvoided": "-0.22%" } }Things done
passthru.tests.nixpkgs-reviewon this PR. See nixpkgs-review usage../result/bin/.