libexpr: add nix-expr-benchmarks, add regex optimizations#14827
Merged
xokdvium merged 3 commits intoNixOS:masterfrom Dec 19, 2025
Merged
libexpr: add nix-expr-benchmarks, add regex optimizations#14827xokdvium merged 3 commits intoNixOS:masterfrom
xokdvium merged 3 commits intoNixOS:masterfrom
Conversation
0c4211c to
16f0fa9
Compare
Member
|
16f0fa9 to
e74e91d
Compare
Member
Author
|
Now the CI is failing because of a GitHub API timeout. Some outage, I've just had a similar issue on one of my repos. |
xokdvium
reviewed
Dec 18, 2025
src/libexpr/primops.cc
Outdated
| boost::concurrent_flat_map<std::string, Entry, StringViewHash, std::equal_to<>> cache; | ||
|
|
||
| std::regex get(std::string_view re) | ||
| std::shared_ptr<const std::regex> get(std::string_view re) |
Contributor
There was a problem hiding this comment.
Maybe instead of shared_ptr we can use nix::ref, which is non-nunnable shared ptr wrapper. Worth noting in a comment somewhere that putting this behind a shared_ptr is necessary because the flat_map can invalidate pointers pretty easily.
xokdvium
reviewed
Dec 18, 2025
e74e91d to
7e146c2
Compare
Provides focused microbenchmarks for expression evaluation hot paths (dynamic attrs, getDerivations attr scanning, and repeated builtins.match).
- RegexCache::get() returned std::regex by value, copying the compiled regex on every cache hit. - Store the compiled regex behind std::shared_ptr<const std::regex> and return the shared pointer instead, so callers reuse the same compiled object. - BM_EvalManyBuiltinsMatchSameRegex_mean improved about 8%
- getDerivations() filters attribute names with std::regex_match, which runs the regex engine for every attribute visited during nixpkgs scanning. - BM_GetDerivationsAttrScan/10000_mean: 3.338 ms → 1.506 ms (≈ -54.9%)
7e146c2 to
048d0b6
Compare
xokdvium
approved these changes
Dec 19, 2025
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.
Instead of reading this PR, please read the individual commits. The latter 2 changes depend on the new benchmark module for libexpr. These are regex oriented optimizations. There is a big performance win for accessing attributes (regex validation engine was heavy).
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.