Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Change the return type of step_inner function. #10940

Merged
merged 2 commits into from
Aug 5, 2019

Conversation

aoli-al
Copy link
Contributor

@aoli-al aoli-al commented Aug 3, 2019

This PR simplifies the return result of step_inner function.

Using Result<Never, InterpreterResult> as return result will cause
unnecessary overhead (mostly additional memory operations). Since
step_inner is a hot function, I propose to simplify the return type of
step_inner function and handle the error results manually.

Some benchmark results I have:

Without Optimization (Original Version):
test rng_u256 ... bench: 68,395,922 ns/iter (+/- 19,520,348)
test rng_usize ... bench: 46,822,703 ns/iter (+/- 19,869,026)
test simple_loop_u256 ... bench: 18,807,019 ns/iter (+/- 5,683,907)
test simple_loop_usize ... bench: 13,812,568 ns/iter (+/- 3,310,862)

With Optimization:
test rng_u256 ... bench: 53,654,255 ns/iter (+/- 12,985,727)
test rng_usize ... bench: 36,481,886 ns/iter (+/- 13,044,046)
test simple_loop_u256 ... bench: 15,010,101 ns/iter (+/- 5,306,132)
test simple_loop_usize ... bench: 10,584,103 ns/iter (+/- 2,439,375)

Some perf results I have:

image

@parity-cla-bot
Copy link

It looks like @Leeleo3x hasn't signed our Contributor License Agreement, yet.

The purpose of a CLA is to ensure that the guardian of a project's outputs has the necessary ownership or grants of rights over all contributions to allow them to distribute under the chosen licence.
Wikipedia

You can read and sign our full Contributor License Agreement at the following URL: https://cla.parity.io

Once you've signed, please reply to this thread with [clabot:check] to prove it.

Many thanks,

Parity Technologies CLA Bot

@aoli-al
Copy link
Contributor Author

aoli-al commented Aug 3, 2019

[clabot:check]

@parity-cla-bot
Copy link

It looks like @Leeleo3x signed our Contributor License Agreement. 👍

Many thanks,

Parity Technologies CLA Bot

@jam10o-new jam10o-new added A0-pleasereview 🤓 Pull request needs code review. F7-optimisation 💊 An enhancement to provide better overall performance in terms of time-to-completion for a task. labels Aug 3, 2019
@jam10o-new jam10o-new added this to the 2.7 milestone Aug 3, 2019
@dvdplm
Copy link
Collaborator

dvdplm commented Aug 5, 2019

Do you mind including the benchmark code in the PR?

Removing the error conversion and all uses of ? makes the code less readable. Can you elaborate on why the return type change necessitates changing the error handling like this?

@aoli-al
Copy link
Contributor Author

aoli-al commented Aug 5, 2019

The benchmark I'm using is included in current Parity code base. To run benchmarks:

cargo bench --package evmbin

I do understand ? operator makes the code more readable. However, the ? operator calls into_result function and wraps the result into Result type which causes additional memory operations. This is also because the size of InterpreterResult is large and need to be stored in memory to be moved around.

@ordian
Copy link
Collaborator

ordian commented Aug 5, 2019

Do you mind including the benchmark code in the PR?

I think the benches are from evmbin/benches/mod.rs.

Removing the error conversion and all uses of ? makes the code less readable. Can you elaborate on why the return type change necessitates changing the error handling like this?

That's a known issue rust-lang/rust#37939

@ordian ordian added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Aug 5, 2019
@dvdplm
Copy link
Collaborator

dvdplm commented Aug 5, 2019

That's a known issue rust-lang/rust#37939

I had no idea, thank you for educating me.

@ddorgan ddorgan closed this Aug 5, 2019
@ddorgan ddorgan reopened this Aug 5, 2019
@ordian ordian merged commit 8e0c522 into openethereum:master Aug 5, 2019
ordian added a commit that referenced this pull request Aug 7, 2019
* master:
  journaldb changes (#10929)
  Allow default block parameter to be blockHash (#10932)
  Enable sealing when engine is ready (#10938)
  Fix some warnings and typos. (#10941)
  Updated security@parity.io key (#10939)
  Change the return type of step_inner function. (#10940)
  get rid of hidden mutability of Spec (#10904)
  simplify BlockReward::reward implementation (#10906)
  Kaspersky AV whitelisting (#10919)
  additional arithmetic EVM opcode benchmarks (#10916)
  [Cargo.lock] cargo update -p crossbeam-epoch (#10921)
  Fixes incorrect comment. (#10913)
  Add file path to disk map write/read warnings (#10911)
s3krit pushed a commit that referenced this pull request Aug 14, 2019
* Change the return type of step_inner function.

* Fix indention.
ordian added a commit that referenced this pull request Aug 15, 2019
* master:
  [evmbin] fix compilation (#10976)
  Update to latest trie version. (#10972)
  [blooms-db] Fix benchmarks (#10974)
  Fix ethcore/benches build. (#10964)
  tx-pool: accept local tx with higher gas price when pool full (#10901)
  Disable unsyncable expanse chain (#10926)
  Extract Machine from ethcore (#10949)
  removed redundant state_root function from spec, improve spec error types (#10955)
  Add support for Energy Web Foundation's new chains (#10957)
  [evmbin] add more tests to main.rs (#10956)
  Fix compiler warnings in util/io and upgrade to edition 2018 Upgrade mio to latest (#10953)
  unify loading spec && further spec cleanups (#10948)
  refactor: Refactor evmbin CLI (#10742)
  journaldb changes (#10929)
  Allow default block parameter to be blockHash (#10932)
  Enable sealing when engine is ready (#10938)
  Fix some warnings and typos. (#10941)
  Updated security@parity.io key (#10939)
  Change the return type of step_inner function. (#10940)
s3krit pushed a commit that referenced this pull request Sep 11, 2019
* Change the return type of step_inner function.

* Fix indention.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well. F7-optimisation 💊 An enhancement to provide better overall performance in terms of time-to-completion for a task.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants