Skip to content

libexpr: add nix-expr-benchmarks, add regex optimizations#14827

Merged
xokdvium merged 3 commits intoNixOS:masterfrom
Zaczero:zaczero/libexpr
Dec 19, 2025
Merged

libexpr: add nix-expr-benchmarks, add regex optimizations#14827
xokdvium merged 3 commits intoNixOS:masterfrom
Zaczero:zaczero/libexpr

Conversation

@Zaczero
Copy link
Member

@Zaczero Zaczero commented Dec 18, 2025

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.

@Mic92
Copy link
Member

Mic92 commented Dec 18, 2025

@Zaczero

   > meson.build:92:3: ERROR: Tried to access unknown option 'benchmarks'.

@Zaczero
Copy link
Member Author

Zaczero commented Dec 18, 2025

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.

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

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%)
@xokdvium xokdvium added this pull request to the merge queue Dec 19, 2025
Merged via the queue into NixOS:master with commit 132a936 Dec 19, 2025
16 checks passed
@Zaczero Zaczero deleted the zaczero/libexpr branch December 19, 2025 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants