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

feat(vm): Improve tracer trait #121

Conversation

Deniallugo
Copy link
Contributor

@Deniallugo Deniallugo commented Sep 29, 2023

What ❔

Changing the way, how tracers are working in VM. Try to make less calls and add more static dispatching

Tracer Api changes:

  1. Method before decoding now always empty (zk_evm don't call it)
  2. Method before cycle doesn't exist anymore
  3. Method after_cycle renamed to finish_cycle and unified with should stop execution
  4. Method save_results was removed
  5. All methods from ExecutionProcessing trait moved to VmTracer

Vm Changes:
Refund tracer now dispatching statically and not dynamically

Why ❔

Checklist

  • PR title corresponds to the body of PR (we generate changelog entries from PRs).
  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.
  • Code has been formatted via zk fmt and zk lint.

@Deniallugo Deniallugo changed the title Mirrors branch deniallugo-vm-perf-optimization from private at 008df6… chore(perf): Remove unnecessary tracer calls Sep 29, 2023
@Deniallugo Deniallugo marked this pull request as draft September 29, 2023 15:26
@Deniallugo Deniallugo force-pushed the mirror-deniallugo-vm-perf-optimization-008df6deb6bd627ec9dc901a78aca374f16fd14e branch from 57259be to aa3172c Compare September 29, 2023 15:56
@codecov
Copy link

codecov bot commented Sep 29, 2023

Codecov Report

Attention: 36 lines in your changes are missing coverage. Please review.

Comparison is base (7e23188) 32.73% compared to head (b266161) 32.75%.
Report is 10 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #121      +/-   ##
==========================================
+ Coverage   32.73%   32.75%   +0.02%     
==========================================
  Files         536      536              
  Lines       28122    28126       +4     
==========================================
+ Hits         9207     9214       +7     
+ Misses      18915    18912       -3     
Files Coverage Δ
core/bin/system-constants-generator/src/utils.rs 0.00% <ø> (ø)
core/lib/vm/src/tracers/call.rs 50.00% <100.00%> (ø)
core/lib/vm/src/tracers/result_tracer.rs 50.00% <ø> (ø)
core/lib/vm/src/tracers/traits.rs 73.33% <85.71%> (-8.49%) ⬇️
core/lib/vm/src/tracers/validation/mod.rs 0.00% <0.00%> (ø)
core/lib/vm/src/tracers/refunds.rs 55.93% <50.00%> (+2.15%) ⬆️
core/lib/vm/src/tracers/storage_invocations.rs 0.00% <0.00%> (ø)
core/lib/vm/src/implementation/execution.rs 48.27% <46.15%> (-3.58%) ⬇️
core/lib/vm/src/tracers/default_tracers.rs 50.96% <45.45%> (+4.42%) ⬆️

... and 8 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Deniallugo Deniallugo force-pushed the mirror-deniallugo-vm-perf-optimization-008df6deb6bd627ec9dc901a78aca374f16fd14e branch from f6ab256 to 63dd153 Compare October 10, 2023 16:05
Signed-off-by: Danil <deniallugo@gmail.com>
Signed-off-by: Danil <deniallugo@gmail.com>
@Deniallugo Deniallugo force-pushed the mirror-deniallugo-vm-perf-optimization-008df6deb6bd627ec9dc901a78aca374f16fd14e branch from 0eabe2a to b54f04a Compare October 10, 2023 17:31
Signed-off-by: Danil <deniallugo@gmail.com>
@Deniallugo Deniallugo force-pushed the mirror-deniallugo-vm-perf-optimization-008df6deb6bd627ec9dc901a78aca374f16fd14e branch 2 times, most recently from dbd8145 to d5aaf93 Compare October 10, 2023 18:07
Signed-off-by: Danil <deniallugo@gmail.com>
@Deniallugo Deniallugo force-pushed the mirror-deniallugo-vm-perf-optimization-008df6deb6bd627ec9dc901a78aca374f16fd14e branch 3 times, most recently from 54aac4a to db319f3 Compare October 11, 2023 14:26
@Deniallugo Deniallugo marked this pull request as ready for review October 11, 2023 14:27
@Deniallugo Deniallugo requested a review from a team as a code owner October 11, 2023 14:27
@mm-zk
Copy link
Collaborator

mm-zk commented Oct 11, 2023

@Deniallugo - can you add more info in the PR description?
which methods you are removing, what are you changing in the API

Halt::ValidationOutOfGas,
));
}
TracerExecutionStatus::Continue
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is a little hard to follow - we do match, don't return only in the Batch variabt, and then do an if. I think it would be cleaner with

match self.execution_mode {
            VmExecutionMode::OneTx if self.tx_has_been_processed() => 
                      TracerExecutionStatus::Stop(TracerExecutionStopReason::Finish)
            }
            VmExecutionMode::Bootloader if self.ret_from_the_bootloader == Some(RetOpcode::Ok) => 
                    TracerExecutionStatus::Stop(TracerExecutionStopReason::Finish);
            }
            VmExecutionMode::Batch if self.validation_run_out_of_gas() => 
TracerExecutionStatus::Stop(TracerExecutionStopReason::Abort(
                Halt::ValidationOutOfGas,
        _ => 
        TracerExecutionStatus::Continue
            
        };

Copy link
Member

Choose a reason for hiding this comment

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

The two variants can be squashed into one i think with |

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have to always check self.validation_run_out_of_gas. Independent from execution_mode.
Thanks for the other suggestions :)

The two variants can be squashed into one i think with |

Only without if..

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why? We dobn't check it now since we return

@RomanBrodetski
Copy link
Collaborator

@Deniallugo can you please explain why the RefundTracer needs to be treated specially?

@Deniallugo
Copy link
Contributor Author

@Deniallugo can you please explain why the RefundTracer needs to be treated specially?

It's an internal tracer for VM and it used almost with all calls and the results of the execution are presented in VmExecutionResultAndLogs

From performance perspective it's better to make it statically dispatched

core/lib/vm/src/tracers/traits.rs Show resolved Hide resolved
core/lib/vm/src/tracers/traits.rs Outdated Show resolved Hide resolved
core/lib/vm/src/tracers/refunds.rs Show resolved Hide resolved
core/lib/vm/src/tracers/default_tracers.rs Show resolved Hide resolved
core/lib/vm/src/implementation/execution.rs Outdated Show resolved Hide resolved
core/lib/vm/src/implementation/execution.rs Outdated Show resolved Hide resolved
Halt::ValidationOutOfGas,
));
}
TracerExecutionStatus::Continue
Copy link
Member

Choose a reason for hiding this comment

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

The two variants can be squashed into one i think with |

Signed-off-by: Danil <deniallugo@gmail.com>
@Deniallugo Deniallugo force-pushed the mirror-deniallugo-vm-perf-optimization-008df6deb6bd627ec9dc901a78aca374f16fd14e branch from db319f3 to a3cab2c Compare October 11, 2023 15:27
montekki
montekki previously approved these changes Oct 11, 2023
core/lib/vm/src/tracers/traits.rs Outdated Show resolved Hide resolved
@Deniallugo Deniallugo force-pushed the mirror-deniallugo-vm-perf-optimization-008df6deb6bd627ec9dc901a78aca374f16fd14e branch from 94c2986 to a8108be Compare October 12, 2023 08:21
Copy link
Contributor

@perekopskiy perekopskiy left a comment

Choose a reason for hiding this comment

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

Looks really nice! Left a couple of nits

core/lib/vm/src/implementation/execution.rs Show resolved Hide resolved
core/lib/vm/src/tracers/traits.rs Outdated Show resolved Hide resolved
Signed-off-by: Danil <deniallugo@gmail.com>
@Deniallugo Deniallugo force-pushed the mirror-deniallugo-vm-perf-optimization-008df6deb6bd627ec9dc901a78aca374f16fd14e branch from a8108be to b266161 Compare October 12, 2023 08:41
@Deniallugo Deniallugo changed the title chore(perf): Remove unnecessary tracer calls feat(vm): Improve tracer trait Oct 12, 2023
@github-actions
Copy link
Contributor

Detected VM performance changes

Benchmark name Difference in runtime
decode_shl_sub -3.3%
event_spam -2.5%
slot_hash_collision -3.2%
access_memory -3.0%
write_and_decode -3.1%

core/lib/vm/src/tracers/traits.rs Show resolved Hide resolved
core/lib/vm/src/tracers/traits.rs Show resolved Hide resolved
core/lib/vm/src/tracers/traits.rs Show resolved Hide resolved
@Deniallugo Deniallugo added this pull request to the merge queue Oct 12, 2023
@Deniallugo Deniallugo removed this pull request from the merge queue due to a manual request Oct 12, 2023
@Deniallugo Deniallugo added this pull request to the merge queue Oct 12, 2023
@Deniallugo Deniallugo removed this pull request from the merge queue due to a manual request Oct 12, 2023
@Deniallugo Deniallugo added this pull request to the merge queue Oct 12, 2023
Merged via the queue into main with commit ff60138 Oct 12, 2023
24 checks passed
@Deniallugo Deniallugo deleted the mirror-deniallugo-vm-perf-optimization-008df6deb6bd627ec9dc901a78aca374f16fd14e branch October 12, 2023 18:51
github-merge-queue bot pushed a commit that referenced this pull request Oct 24, 2023
🤖 I have created a release *beep* *boop*
---


##
[16.1.0](core-v16.0.2...core-v16.1.0)
(2023-10-24)


### Features

* Add new commitments
([#219](#219))
([a19256e](a19256e))
* arm64 zk-environment rust Docker images and other
([#296](#296))
([33174aa](33174aa))
* **config:** Extract everything not related to the env config from
zksync_config crate
([#245](#245))
([42c64e9](42c64e9))
* **eth-watch:** process governor upgrades
([#247](#247))
([d250294](d250294))
* **merkle tree:** Expose Merkle tree API
([#209](#209))
([4010c7e](4010c7e))
* **merkle tree:** Snapshot recovery for Merkle tree
([#163](#163))
([9e20703](9e20703))
* **multivm:** Remove lifetime from multivm
([#218](#218))
([7eda27c](7eda27c))
* Remove fee_ticker and token_trading_volume fetcher modules
([#262](#262))
([44f7179](44f7179))
* **reorg_detector:** compare miniblock hashes for reorg detection
([#236](#236))
([2c930b2](2c930b2))
* Rewrite server binary to use `vise` metrics
([#120](#120))
([26ee1fb](26ee1fb))
* **types:** introduce state diff record type and compression
([#194](#194))
([ccf753c](ccf753c))
* **vm:** Improve tracer trait
([#121](#121))
([ff60138](ff60138))
* **vm:** Move all vm versions to the one crate
([#249](#249))
([e3fb489](e3fb489))


### Bug Fixes

* **crypto:** update snark-vk to be used in server and update args for
proof wrapping
([#240](#240))
([4a5c54c](4a5c54c))
* **db:** Fix write stalls in RocksDB
([#250](#250))
([650124c](650124c))
* **db:** Fix write stalls in RocksDB (again)
([#265](#265))
([7b23ab0](7b23ab0))
* **db:** Fix write stalls in RocksDB (for real this time)
([#292](#292))
([0f15919](0f15919))
* Fix `TxStage` string representation
([#255](#255))
([246b5a0](246b5a0))
* fix typos
([#226](#226))
([feb8a6c](feb8a6c))
* **witness-generator:** Witness generator oracle with cached storage
refunds ([#274](#274))
([8928a41](8928a41))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
ilitteri pushed a commit that referenced this pull request Feb 23, 2024
…mode and Rollup mode (#121)

* Add example: build_commit_tx_input_data_is_correct (fails)

* Abstract normal_checker_function test

* Abstract checker_processes_pre_boojum_batches

* Abstract checker_functions_after_snapshot_recovery test

* Abstract checker_functions_after_snapshot_recovery test

* Remove unnecessary auxiliar function

* Fix all the failing tests

* Use test_helpers module

* Remove ValidiumModeL1BatchCommitDataGenerator fix

* Add bytes pubdata with 0 value for the encoding (#136)
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.

None yet

6 participants