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

Remove tag from RuntimeValue #133

Merged
merged 2 commits into from
Oct 31, 2018

Conversation

eira-fransham
Copy link
Contributor

This closes #99. Benchcmp results:

 name               preopt.bench ns/iter  postopt.bench ns/iter  diff ns/iter   diff %  speedup 
 bench_regex_redux  4,471,532             4,117,821                  -353,711   -7.91%   x 1.09 
 bench_rev_comp     10,363,517            9,552,537                  -810,980   -7.83%   x 1.08 
 bench_tiny_keccak  5,475,809             5,044,934                  -430,875   -7.87%   x 1.09 
 fac_opt            42,472                26,942                      -15,530  -36.57%   x 1.58 
 fac_recursive      43,852                28,770                      -15,082  -34.39%   x 1.52 
 recursive_ok       1,423,602             1,363,951                   -59,651   -4.19%   x 1.04 
 recursive_trap     182,536               160,872                     -21,664  -11.87%   x 1.13 

All tests still pass. I expect most of these improvements are due to the fact that we double our cache efficiency by halving the size of RuntimeValue (since RuntimeValue includes a u64, its tag must be padded to 64 bits, making the whole value 2x the size of a u64). However, some improvements may be due to the fact that we remove some validity checking on function arguments. This was duplicated effort anyway, since that is already checked statically.

src/value.rs Outdated
@@ -28,6 +29,93 @@ pub enum RuntimeValue {
F64(F64),
}

#[derive(Copy, Clone, Debug, PartialEq, Default)]
pub(crate) struct RuntimeValueInternal(pub u64);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add a brief comment what is going on here and why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great point, this is definitely not self-explanatory

@pepyakin
Copy link
Collaborator

Could you rebase this please?

@eira-fransham
Copy link
Contributor Author

eira-fransham commented Oct 29, 2018

Per mine and @pepyakin's discussion in private, we seem to get such a huge improvement on the factorial benchmarks because zeroing allocation can use memset/calloc now instead of having to write bytes individually. Before it was setting stack values to I32(0), which (evidently) doesn't have the tag 0 and so memset(0) wouldn't work, but now because it's essentially just writing a zeroed u64 Rust can generate a memset or calloc (depending on whether we're on the stack or the heap, respectively).

@pepyakin
Copy link
Collaborator

Could you rebase this?

@eira-fransham
Copy link
Contributor Author

@pepyakin After this rebase can you just squash+merge (unless it's incorrect of course) because I have to manually merge every time because all our changes touch runner.rs

@pepyakin
Copy link
Collaborator

yeah sure! Just ping me in every possible way you can whenever you've done with rebasing : )

@pepyakin pepyakin merged commit c877d64 into wasmi-labs:master Oct 31, 2018
@pepyakin
Copy link
Collaborator

Perfect, thank you!

eira-fransham added a commit to eira-fransham/wasmi that referenced this pull request Nov 21, 2018
* Remove tag from runtime value

* Add explanation of `RuntimeValueInternal`, move it so I don't need to do `pub(crate)`
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.

Optimization: use unions for representing RuntimeValue
2 participants