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

Faster kill_garbage #11514

Merged
merged 4 commits into from
Feb 27, 2020
Merged

Faster kill_garbage #11514

merged 4 commits into from
Feb 27, 2020

Conversation

dvdplm
Copy link
Collaborator

@dvdplm dvdplm commented Feb 24, 2020

Profiling the benchmark from #11509 shows that almost half the time apply()-ing a transaction is spent in garbage collection. This PR avoids visiting each cache item and collect()-ing accounts to clean up.

apply transactions with tracing (Constantinople)
                        time:   [771.87 us 785.31 us 799.39 us]
                        change: [-1.6171% +0.8871% +3.4408%] (p = 0.49 > 0.05)
                        No change in performance detected.
Found 6 outliers among 100 measurements (6.00%)
  6 (6.00%) high mild

apply transactions without tracing (Constantinople)
                        time:   [624.40 us 632.38 us 640.60 us]
                        change: [-3.7894% -1.7770% +0.2331%] (p = 0.09 > 0.05)
                        No change in performance detected.

apply transactions with tracing (Istanbul)
                        time:   [603.13 us 611.19 us 619.69 us]
                        change: [+0.6069% +3.1495% +5.9820%] (p = 0.02 < 0.05)
                        Change within noise threshold.
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild

apply transactions without tracing (Istanbul)
                        time:   [490.90 us 498.22 us 505.93 us]
                        change: [-0.6020% +1.4944% +3.7714%] (p = 0.19 > 0.05)
                        No change in performance detected.
Found 3 outliers among 100 measurements (3.00%)
  3 (3.00%) high mild

Before this PR:

apply transactions with tracing (Constantinople)
                        time:   [2.0166 ms 2.0470 ms 2.0807 ms]
                        change: [-1.1628% +1.1355% +3.8393%] (p = 0.38 > 0.05)
                        No change in performance detected.
Found 12 outliers among 100 measurements (12.00%)
  12 (12.00%) high mild

Benchmarking apply transactions without tracing (Constantinople): Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 9.7s or reduce sample count to 50.
apply transactions without tracing (Constantinople)
                        time:   [1.8491 ms 1.8758 ms 1.9056 ms]
                        change: [-3.5325% -1.0900% +1.4900%] (p = 0.40 > 0.05)
                        No change in performance detected.
Found 10 outliers among 100 measurements (10.00%)
  6 (6.00%) high mild
  4 (4.00%) high severe

Benchmarking apply transactions with tracing (Istanbul): Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 6.4s or reduce sample count to 60.
apply transactions with tracing (Istanbul)
                        time:   [1.2220 ms 1.2451 ms 1.2708 ms]
                        change: [-6.6992% -3.7312% -0.7610%] (p = 0.02 < 0.05)
                        Change within noise threshold.
Found 8 outliers among 100 measurements (8.00%)
  6 (6.00%) high mild
  2 (2.00%) high severe

Benchmarking apply transactions without tracing (Istanbul): Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 5.7s or reduce sample count to 60.
apply transactions without tracing (Istanbul)
                        time:   [1.0961 ms 1.1153 ms 1.1382 ms]
                        change: [-1.6498% +0.7117% +3.0664%] (p = 0.57 > 0.05)
                        No change in performance detected.
Found 14 outliers among 100 measurements (14.00%)
  6 (6.00%) high mild
  8 (8.00%) high severe

Benchmark shows that almost half the time `apply()`-ing a transaction is spent in garbage collection. This PR avoids visiting each cache item and `collect()`-ing accounts to clean up.
@dvdplm dvdplm self-assigned this Feb 24, 2020
@dvdplm dvdplm added the A0-pleasereview 🤓 Pull request needs code review. label Feb 24, 2020
@dvdplm dvdplm requested review from arkpar and ordian and removed request for arkpar February 24, 2020 18:43
@ordian
Copy link
Collaborator

ordian commented Feb 24, 2020

No change in performance detected.

But if there is no perf improvement, what's the point?

@ordian
Copy link
Collaborator

ordian commented Feb 24, 2020

No change in performance detected.

But if there is no perf improvement, what's the point?

Ah, sorry, now I see it's actually faster, should have looked at the absolute numbers.

Test failure is legit though.

@ordian ordian added the A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. label Feb 25, 2020
* master:
  Add benchmark for transaction execution (#11509)
  Add Smart Contract License v1.0
pub fn kill_garbage(&mut self, touched: &HashSet<Address>, min_balance: &Option<U256>, kill_contracts: bool) -> TrieResult<()> {
let to_kill: HashSet<_> =
touched.iter().filter_map(|address| { // Check all touched accounts
self.cache.borrow().get(address).and_then(|entry| {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I collected some more stats on the size of the cache on current mainnet. On the blocks I saw the cache length is invariably higher than size of the touched collection so I think this change – looping over touched rather than over the cached items – is good.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

touched is mostly 1, sometimes it goes up to ~10, rarely to ~50. The cache length is between a few tens to a few hundreds.

@dvdplm dvdplm removed the A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. label Feb 27, 2020
@ordian ordian merged commit 8572d61 into master Feb 27, 2020
@ordian ordian deleted the dp/perf/faster-kill_garbage branch February 27, 2020 12:56
@ordian ordian added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Feb 27, 2020
ordian added a commit that referenced this pull request Mar 6, 2020
* master: (27 commits)
  Faster kill_garbage (#11514)
  [EngineSigner]: don't sign message with only zeroes (#11524)
  fix compilation warnings (#11522)
  [ethcore cleanup]: various unrelated fixes from `#11493` (#11507)
  Add benchmark for transaction execution (#11509)
  Add Smart Contract License v1.0
  Misc fixes (#11510)
  [dependencies]: unify `rustc-hex` (#11506)
  Activate on-chain randomness in POA Sokol (#11505)
  Grab bag of cleanup (#11504)
  Implement eth/64 (EIP-2364) and drop support for eth/62 (#11472)
  [dependencies]: remove `util/macros` (#11501)
  OpenEthereum bootnodes are added (#11499)
  [ci benches]: use `all-features` (#11496)
  [verification]: make test-build compile standalone (#11495)
  complete null-signatures removal (#11491)
  Include the seal when populating the header for a new block (#11475)
  fix compilation warnings (#11492)
  cargo update -p cmake (#11490)
  update to published rlp-derive (#11489)
  ...
ordian added a commit that referenced this pull request Mar 10, 2020
* master:
  Code cleanup in the sync module (#11552)
  initial cleanup (#11542)
  Warn if genesis constructor revert (#11550)
  ethcore: cleanup after #11531 (#11546)
  license update (#11543)
  Less cloning when importing blocks (#11531)
  Github Actions (#11528)
  Fix Alpine Dockerfile (#11538)
  Remove AuxiliaryData/AuxiliaryRequest (#11533)
  [journaldb]: cleanup (#11534)
  Remove references to parity-ethereum (#11525)
  Drop IPFS support (#11532)
  chain-supplier: fix warning reporting for GetNodeData request (#11530)
  Faster kill_garbage (#11514)
  [EngineSigner]: don't sign message with only zeroes (#11524)
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants