1
- # Addition of ` VisitedPcs ` trait
1
+ # Adding the ` VisitedPcs ` Trait
2
2
3
- Current blockifier doesn't store the complete vector of visited program counters
4
- for each entry point call in an invoke transaction. Instead, visited program
5
- counters are pushed in a ` HashSet ` . This is a limiting factor to perform
6
- profiling operations which require record of the full trace returned by
7
- ` cairo-vm ` . More flexibility is added to the blockifier with the introduction of
8
- trait ` VisitedPcs ` which allows the user to process visited program counters in
9
- the most suitable way for the task.
3
+ The state of the blockifier as of commit
4
+ ` 14e6a87722c1d0c757b1aa2756ffabe3f248fd7d ` doesn't store the complete vector of
5
+ visited program counters for each entry-point in an invoke transaction. Instead,
6
+ visited program counters are pushed into a ` HashSet ` . Unfortunately this limits
7
+ the ability to perform profiling operations, as many require a record of the
8
+ full trace returned from the ` cairo-vm ` .
10
9
11
- ## Existing code
10
+ In order to enable more in-depth tracing use-cases, we have introduced the
11
+ ` VisitedPcs ` trait which allows the user to process the visited program counters
12
+ as they see fit.
13
+
14
+ ## Old Code
12
15
13
16
Visited program counters are kept in the ` CachedState ` structure as shown below:
14
17
@@ -25,9 +28,18 @@ pub struct CachedState<S: StateReader> {
25
28
}
26
29
```
27
30
28
- ## New code
31
+ This snipped has been extracted from commit
32
+ [ 14e6a87722c1d0c757b1aa2756ffabe3f248fd7d] ( https://github.com/reilabs/blockifier/blob/14e6a87722c1d0c757b1aa2756ffabe3f248fd7d/crates/blockifier/src/state/cached_state.rs#L36 )
33
+
34
+ ## New Code
29
35
30
- ` VisitedPcs ` is an additional generic parameter of ` CachedState ` .
36
+ > [ !NOTE]
37
+ > The new code is developed in the branch ` visited_pcs_trait ` and the
38
+ > current head of the branch is at commit
39
+ > [ ` bdb1b49331aad91d445ac2155baa40fa783bcf7f ` ] ( https://github.com/reilabs/blockifier/blob/visited_pcs_trait/crates/blockifier/src/state/cached_state.rs#L37 ) .
40
+ > This will change once these changes are merged in the main branch.
41
+
42
+ ` VisitedPcs ` is added as an additional generic parameter of ` CachedState ` .
31
43
32
44
``` rust
33
45
#[derive(Debug )]
@@ -43,51 +55,57 @@ pub struct CachedState<S: StateReader, V: VisitedPcs> {
43
55
```
44
56
45
57
An implementation of the trait ` VisitedPcs ` is included in the blockifier with
46
- the name ` VisitedPcsSet ` and it mimics the existing ` HashSet<usize> ` . Also, for
47
- test purposes, ` CachedState ` is instantiated using ` VisitedPcsSet ` .
58
+ the name ` VisitedPcsSet ` . This mimics the existing ` HashSet<usize> ` usage of
59
+ this field. For test purposes, ` CachedState ` is instantiated using
60
+ ` VisitedPcsSet ` .
48
61
49
- ## Performance considerations
62
+ ## Performance Considerations
50
63
51
- Given the importance of the blockifier in the Starknet ecosystem, we want to
52
- measure the performance impact of adding the trait ` VisitedPcs ` . The existing
53
- bechmark ` transfers ` doesn't cover operations with ` CachedState ` therefore we
54
- need to design new ones. We have created two new benchmarks :
64
+ Given the importance of the blockifier's performance in the Starknet ecosystem,
65
+ measuring the impact of adding the aforementioned ` VisitedPcs ` trait is very
66
+ important. The existing bechmark ` transfers ` doesn't cover operations that use
67
+ the ` CachedState ` , and therefore we have designed new ones as follows :
55
68
56
69
- ` cached_state ` : this benchmark tests the performance impact of populating
57
70
` visited_pcs ` (implemented using ` VisitedPcsSet ` ) with a realistic amount of
58
71
visited program counters. The size of the sets is taken from transaction
59
- ` 0x0177C9365875CAA840EA8F03F97B0E3A8EE8851A8B952BF157B5DBD4FECCB060 ` in the
60
- mainnet. This transaction has been chosen randomly, but there is no assurance
72
+ ` 0x0177C9365875CAA840EA8F03F97B0E3A8EE8851A8B952BF157B5DBD4FECCB060 ` on
73
+ mainnet. This transaction has been chosen randomly but there is no assurance
61
74
that it's representative of the most common Starknet invoke transaction. This
62
75
benchmark tests the write performance of visited program counters in the state
63
76
struct.
64
77
- ` execution ` : this benchmark simulates a whole invoke transaction using a dummy
65
78
contract.
66
79
67
- ## Performance impact
80
+ ## Performance Impact
68
81
69
- A script ` bench.sh ` has been added to benchmark the performance impact of these
70
- changes: it is called as
71
- ` bash scripts/bench.sh 14e6a87722c1d0c757b1aa2756ffabe3f248fd7d e39ae0be4cec31938399199e0a1070279b4a78ed ` .
72
- The computer running the benchmark is: Debian VM over Windows 10 with VMWare
73
- Workstation 17, i9-9900K, 64GB RAM, Samsung 990 Pro NVME SSD.
82
+ The ` bench.sh ` script has been added to benchmark the performance impact of
83
+ these changes.
74
84
75
- The Rust toolchain used is:
76
- ```
77
- 1.78-x86_64-unknown-linux-gnu (default)
78
- rustc 1.78.0 (9b00956e5 2024-04-29)
79
- ```
85
+ The benchmark results presented below were conducted under the following
86
+ conditions:
87
+
88
+ - ** Operating System:** Debian 12 (Bookworm) running in a VMWare Workstation 17
89
+ VM on Windows 10 22H2
90
+ - ** Hardware:** i9-9900K @ 5.0 GHz, 64GB of RAM, Samsung 990 Pro NVMe SSD.
91
+ - ** Rust Toolchain:** 1.78-x86_64-unknown-linux-gnu / rust 1.78.0 (9b00956e5
92
+ 2024-04-29).
93
+
94
+ The script was called as follows, but you may need to [ adjust the commit
95
+ hashes] ( #new-code ) in question to reproduce these results:
96
+
97
+ ` bash scripts/bench.sh 14e6a87722c1d0c757b1aa2756ffabe3f248fd7d e39ae0be4cec31938399199e0a1070279b4a78ed `
80
98
81
- Noise threshold and confidence intervals are kept as per default Criterion.rs
82
- configuration.
99
+ The noise threshold and confidence intervals are kept as per default
100
+ Criterion.rs configuration.
83
101
84
- The results are shown in the following table :
102
+ The results are as follows :
85
103
86
104
| Benchmark | Time (ms) | Time change (%) | Criterion.rs report |
87
105
| ------------ | --------- | --------------- | ----------------------------- |
88
106
| transfers | 94.448 | +0.1080 | No change in performance |
89
107
| execution | 1.2882 | -1.7216 | Change within noise threshold |
90
108
| cached_state | 5.2330 | -0.8703 | No change in performance |
91
109
92
- The analysis of Criterion.rs determines that there isn't statistically
93
- significant performance decrese .
110
+ Criterion's inbuilt confidence analysis suggests that these results have no
111
+ statistical significant and do not represent real-world performance changes .
0 commit comments