Skip to content

Optimize primop calls#5501

Merged
edolstra merged 7 commits intoNixOS:masterfrom
edolstra:optimize-calls
Nov 5, 2021
Merged

Optimize primop calls#5501
edolstra merged 7 commits intoNixOS:masterfrom
edolstra:optimize-calls

Conversation

@edolstra
Copy link
Member

@edolstra edolstra commented Nov 4, 2021

We now parse function applications as a vector of arguments rather than as a chain of binary applications, e.g. substring 1 2 "foo" is parsed as

ExprCall { .fun = <substring>, .args = [ <1>, <2>, <"foo"> ] }

rather than

ExprApp (ExprApp (ExprApp <substring> <1>) <2>) <"foo">

This allows primops to be called immediately (if enough arguments are supplied) without having to allocate intermediate tPrimOpApp values.

Extracted from #3718.

We now parse function applications as a vector of arguments rather
than as a chain of binary applications, e.g. 'substring 1 2 "foo"' is
parsed as

  ExprCall { .fun = <substring>, .args = [ <1>, <2>, <"foo"> ] }

rather than

  ExprApp (ExprApp (ExprApp <substring> <1>) <2>) <"foo">

This allows primops to be called immediately (if enough arguments are
supplied) without having to allocate intermediate tPrimOpApp values.

On

  $ nix-instantiate --dry-run '<nixpkgs/nixos/release-combined.nix>' -A nixos.tests.simple.x86_64-linux

this gives a substantial performance improvement:

  user CPU time:      median =      0.9209  mean =      0.9218  stddev =      0.0073  min =      0.9086  max =      0.9340  [rejected, p=0.00000, Δ=-0.21433±0.00677]
  elapsed time:       median =      1.0585  mean =      1.0584  stddev =      0.0024  min =      1.0523  max =      1.0623  [rejected, p=0.00000, Δ=-0.20594±0.00236]

because it reduces the number of tPrimOpApp allocations from 551990 to
42534 (i.e. only small minority of primop calls are partially
applied) which in turn reduces time spent in the garbage collector.
@edolstra edolstra merged commit a1c1b0e into NixOS:master Nov 5, 2021
@edolstra edolstra deleted the optimize-calls branch November 5, 2021 11:57
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/tweag-nix-dev-update-21/16032/1

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.

2 participants