mirror of
https://github.com/NixOS/nix
synced 2025-06-25 10:41:16 +02:00
libexpr: Improve lexer performance by using full scanner tables (-Cf)
This trades off some executable size for measurable lexer performance improvements. Note on the explicitly enabling 8bit scanner. This is needed due to the default behavior of flex (excerpt from the manual [1]): > Flex’s default behavior is to generate an 8-bit scanner unless you > use the ‘-Cf’ or ‘-CF’, in which case flex defaults to generating > 7-bit scanners unless your site was always configured to generate 8-bit > scanners. Some quantifyable metrics: Nixpkgs revision: a6e3f45acf4e817532a861ab0eda4ab5485fecc1 Parsing the largest file in nixpkgs: pkgs/development/haskell-modules/hackage-packages.nix. (Before this patch) ``` $ nix build github:nixos/nix/9fe3077d4#nix-expr $ du --apparent-size result/lib/libnixexpr.so 2518 result/lib/libnixexpr.so $ nix build github:nixos/nix/9fe3077d4#nix-cli $ taskset -c 2,3 hyperfine "GC_INITIAL_HEAP_SIZE=16g \ result/bin/nix-instantiate --parse \ ../nixpkgs/pkgs/development/haskell-modules/hackage-packages.nix > /dev/null" Time (mean ± σ): 375.5 ms ± 6.3 ms [User: 316.9 ms, System: 56.7 ms] Range (min … max): 368.5 ms … 388.3 ms 10 runs ``` (After the patch) ``` $ nix build .#nix-expr $ du --apparent-size result/lib/libnixexpr.so 2685 result/lib/libnixexpr.so $ nix build .#nix-cli $ taskset -c 2,3 hyperfine "GC_INITIAL_HEAP_SIZE=16g \ result/bin/nix-instantiate --parse \ ../nixpkgs/pkgs/development/haskell-modules/hackage-packages.nix > /dev/null" Time (mean ± σ): 326.8 ms ± 4.9 ms [User: 269.5 ms, System: 55.3 ms] Range (min … max): 319.7 ms … 335.5 ms 10 runs ``` Overall, the change is roughly: - 2518KiB -> 2685KiB ~ 150 KiB of machine code - 375ms -> 325ms ~ 50ms The perf uplift for eval-heavy test cases is obviously less noticeable, but it doesn't make sense not to take this free perf win. [1]: https://westes.github.io/flex/manual/Options-Affecting-Scanner-Behavior.html#Options-Affecting-Scanner-Behavior
This commit is contained in:
parent
9fe3077d47
commit
86a3fad085
2 changed files with 2 additions and 0 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
%option 8bit
|
||||||
%option reentrant bison-bridge bison-locations
|
%option reentrant bison-bridge bison-locations
|
||||||
%option align
|
%option align
|
||||||
%option noyywrap
|
%option noyywrap
|
||||||
|
|
|
@ -112,6 +112,7 @@ lexer_tab = custom_target(
|
||||||
],
|
],
|
||||||
command : [
|
command : [
|
||||||
'flex',
|
'flex',
|
||||||
|
'-Cf', # Use full scanner tables
|
||||||
'--outfile',
|
'--outfile',
|
||||||
'@OUTPUT0@',
|
'@OUTPUT0@',
|
||||||
'--header-file=' + '@OUTPUT1@',
|
'--header-file=' + '@OUTPUT1@',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue