Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor interpreter performance improvements #1876

Merged
merged 6 commits into from Feb 19, 2018
Merged

Conversation

dezgeg
Copy link
Contributor

@dezgeg dezgeg commented Feb 17, 2018

Overall effect on runtime (running nix-instantiate nixos/release.nix -A tests.plasma5.x86_64-linux --dry-run on my old Sandy Bridge laptop):

x before
+ after
+--------------------------------------------------------------------------------------------------------------------------------+
|         +                                                                                               x                      |
|         +                                                                                               x                      |
|         +                                                                                               x                      |
|         +                                                                                               x                      |
|         + +                                                                                          x  x                      |
|         + +                                                                                          x  x                      |
|      +  +++ +                                                                                        x xx                      |
|      +  +++ +                                                                                       xxxxxx                     |
|      ++ +++ ++                                                                                      xxxxxx                     |
|    + ++ +++ ++                                                                                    x xxxxxxx                    |
|    ++++ ++++++                                                                                    xxxxxxxxx                    |
|    ++++ ++++++                                                                                   xxxxxxxxxx                    |
|    +++++++++++ +                                                                                 xxxxxxxxxx                    |
|  + +++++++++++++                                                                               x xxxxxxxxxxxx x     x          |
|+++++++++++++++++    +   +         +                                                          xxxxxxxxxxxxxxxxxxxxx  xx        x|
|     |___MA____|                                                                                   |____A____|                  |
+--------------------------------------------------------------------------------------------------------------------------------+
    N           Min           Max        Median           Avg        Stddev
x  99     3.2504922     3.2697244     3.2563152     3.2564287  0.0029032644
+  99     3.1960438     3.2165469     3.2015429     3.2017174  0.0028051795
Difference at 95.0% confidence
	-0.0547113 +/- 0.000795253
	-1.6801% +/- 0.024421%
	(Student's t, pooled s = 0.00285464)

Per-commit Callgrind cycles:

    3a5a241b: 15409598421 cycles (baseline)             | Merge pull request #1873 from matthewbauer/fix-manpath
    f67a7007: 15403197752 cycles ( -6400669 / -0.04 %)  | libexpr: Pre-reserve space in string in unescapeStr()
    b8bed7da: 15336553144 cycles (-66644608 / -0.43 %)  | libexpr: Optimize prim_attrNames a bit
    0845cdf9: 15303497157 cycles (-33055987 / -0.22 %)  | libexpr: Rely on Boehm returning zeroed memory in EvalState::allocEnv()
    7e036050: 15251705310 cycles (-51791847 / -0.34 %)  | libexpr: Optimize prim_derivationStrict by using more symbol comparisons
    66eeff33: 15249753456 cycles ( -1951854 / -0.01 %)  | libexpr: Remove unnecessary drvName assignment in prim_derivationStrict
    37264ed0: 15210747755 cycles (-39005701 / -0.26 %)  | libexpr: Avoid an unnecessary string copy in prim_derivationStrict

Overall effect in Callgrind cycles:

    15409598421 -> 15210747755 (-198850666 / -1.29 %)

cc @edolstra @shlevy

Instead of having lexicographicOrder() create a temporary sorted array
of Attr*:s and copying attr names from that, copy the attr names
first and then sort that.
Boehm guarantees that memory returned by GC_malloc() is zeroed, so take
advantage of that.
drvName is already assigned to the same value right at the start of the
function.
@shlevy
Copy link
Member

shlevy commented Feb 17, 2018

@dezgeg Thanks! Would you mind showing per-commit profiling? Or is there some reason to think these are synergistic?

@dezgeg
Copy link
Contributor Author

dezgeg commented Feb 19, 2018

They are:

3.256 (baseline) | Merge pull request #1873 from matthewbauer/fix-manpath
3.253  -0.11 %   | libexpr: Pre-reserve space in string in unescapeStr()
3.232  -0.64 %   | libexpr: Optimize prim_attrNames a bit
3.224  -0.27 %   | libexpr: Rely on Boehm returning zeroed memory in EvalState::allocEnv()
3.219  -0.16 %   | libexpr: Optimize prim_derivationStrict by using more symbol comparisons
3.221  +0.06 %   | libexpr: Remove unnecessary drvName assignment in prim_derivationStrict
3.202  -0.57 %   | libexpr: Avoid an unnecessary string copy in prim_derivationStrict

Which have the roughly same orders of magnitude except with more random variation (especially on the "libexpr: Remove unnecessary drvName assignment in prim_derivationStrict" one).

@shlevy shlevy merged commit 37264ed into NixOS:master Feb 19, 2018
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.

None yet

2 participants