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

clif-backend: Eliminate FunctionEnvironment construction in feed_event() #615

Merged
merged 2 commits into from
Aug 1, 2019

Conversation

penberg
Copy link
Contributor

@penberg penberg commented Aug 1, 2019

The feed_event() function is called for every wasm binary instruction.
Let's optimize it by storing FunctionEnvironment object in
CraneliftFunctionCodeGenerator, rather than constructing it for every
feed_event() invocation.

This change reduces the time to run "ngix compile" benchmark by 68%:

Before:

  nginx compile           time:   [1.4152 s 1.4186 s 1.4222 s]
  Found 1 outliers among 10 measurements (10.00%)
    1 (10.00%) high mild

After:

  nginx compile           time:   [447.76 ms 448.32 ms 448.80 ms]
                          change: [-68.542% -68.440% -68.352%] (p = 0.00 < 0.05)
                          Performance has improved.

I assume some of the clone() calls are very expensive (Vec::clone(),
likely). I did see libc malloc()/free() high up in "perf top" profiles,
which are eliminted by this change.

I also looked into eliminating FunctionBuilder construction from
feed_event(). That turns out to be painful on lifetime rules because it
borrows bunch of other objects, so I am leaving it for someone who knows
the code better than I do.

The feed_event() function is called for every wasm binary instruction.
Let's optimize it by storing FunctionEnvironment object in
CraneliftFunctionCodeGenerator, rather than constructing it for every
feed_event() invocation.

This change reduces the time to run "ngix compile" benchmark by 68%:

Before:

  nginx compile           time:   [1.4152 s 1.4186 s 1.4222 s]
  Found 1 outliers among 10 measurements (10.00%)
    1 (10.00%) high mild

After:

  nginx compile           time:   [447.76 ms 448.32 ms 448.80 ms]
                          change: [-68.542% -68.440% -68.352%] (p = 0.00 < 0.05)
                          Performance has improved.

I assume some of the clone() calls are very expensive (Vec::clone(),
likely). I did see libc malloc()/free() high up in "perf top" profiles,
which are eliminted by this change.

I also looked into eliminating FunctionBuilder construction from
feed_event(). That turns out to be painful on lifetime rules because it
borrows bunch of other objects, so I am leaving it for someone who knows
the code better than I do.
@bjfish
Copy link
Contributor

bjfish commented Aug 1, 2019

bors try

bors bot added a commit that referenced this pull request Aug 1, 2019
@syrusakbary
Copy link
Member

I'm following up with some of the changes that were done in this commit to move FunctionBuilder out of the feed_event: d440776

@syrusakbary
Copy link
Member

syrusakbary commented Aug 1, 2019

After talking offline we decided to merge this PR and work on refactoring the clif backend in a separate PR so we can also move FunctionBuilder construction out of the feed_event

@syrusakbary syrusakbary merged commit a9e3eba into wasmerio:master Aug 1, 2019
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