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

Optimization: Modify Heap read and write related functions (wip) #206

Closed
wants to merge 48 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
5a70a25
fix: code-page reads must always succeed
Oppen Aug 13, 2024
6b71882
submodules: add zksync-era submodule
fkrause98 Aug 13, 2024
46cafc3
makefile: bench targets
fkrause98 Aug 13, 2024
f55a4be
makefile: some more bench targets
fkrause98 Aug 14, 2024
393cbbc
ci: add bench setup step
fkrause98 Aug 14, 2024
a380c1c
Merge branch 'main' into ci/add_era_benches
fkrause98 Aug 14, 2024
9983f13
ci: add run bench step
fkrause98 Aug 14, 2024
d6e9014
ci: add checkout sources step
fkrause98 Aug 14, 2024
50e780e
makefile: use frozen-lockfile for yarn
fkrause98 Aug 14, 2024
5105873
ci: add run benchmark
fkrause98 Aug 14, 2024
c3c9984
ci: add toolchain file
fkrause98 Aug 14, 2024
9b17230
ci: use rust toolchain from zksync-era file
fkrause98 Aug 14, 2024
42a63d9
ci: fix bench step
fkrause98 Aug 14, 2024
4c0b869
ci: use manual cache for contract artifacts
fkrause98 Aug 14, 2024
f7155ad
ci: simplify cache
fkrause98 Aug 14, 2024
42bbd95
ci: reuse cache if exists
fkrause98 Aug 14, 2024
65be7b2
ci: restore compiler tester tests
fkrause98 Aug 14, 2024
282247e
zksync-era: bump commit
fkrause98 Aug 14, 2024
c3654fe
ci: use always same cache for contracts
fkrause98 Aug 15, 2024
e38b8ba
lint: unused import
fkrause98 Aug 15, 2024
5ab19ad
ci: debug bench output file
fkrause98 Aug 15, 2024
02c4609
Add makefile benchmarking commands
Aug 16, 2024
ee9f93a
Modify zksync-era commit pointer
Aug 16, 2024
31e0dda
Merge from main
Aug 19, 2024
18fb45c
Update zksync-era submodule pointer
Aug 19, 2024
ba6442e
Update zksync-era commit pointer
Aug 19, 2024
2bbeea0
ci: debug output
fkrause98 Aug 19, 2024
68c14c8
Merge branch 'main' into ci/add_era_benches
fkrause98 Aug 19, 2024
5522d82
ci: fix yml
fkrause98 Aug 19, 2024
9a0cd5b
ci: fix yml
fkrause98 Aug 19, 2024
9da68be
zksync-era: restore commit to integration
fkrause98 Aug 19, 2024
c52cd9c
Update zksync-era commit pointer
Aug 19, 2024
399ccce
Update zksync-era commit pointer
Aug 19, 2024
9192be5
Modify heap read function
Aug 19, 2024
82c6c47
ci: bump zksync-era
fkrause98 Aug 19, 2024
3adfd4f
Add `read_unaligned_from_pointer` optimization
Aug 20, 2024
f8d2cde
Optimize `read_from_pointer`
Aug 20, 2024
4f7cba7
Optimize `Heap::store`
Aug 20, 2024
59429a4
submodules: bump zksync-era commit
fkrause98 Aug 20, 2024
bec791c
ci: bump era
fkrause98 Aug 20, 2024
00f59ff
Update zksync-era commit pointer
Aug 21, 2024
c614f37
Add makefile benchmarking commands
Aug 21, 2024
4042b03
Merge from ci/add_era_benches
Aug 21, 2024
c7d4e70
ci: build benchmarks only for now
fkrause98 Aug 21, 2024
e0cbb4e
Merge branch 'ci/add_era_benches' of github.com:lambdaclass/era_vm in…
Aug 21, 2024
3884d36
Merge branch 'ci/add_era_benches' into bench/heap-read-store
Aug 21, 2024
c4a3c84
Merge branch 'main' into bench/heap-read-store
fkrause98 Aug 26, 2024
6cf6496
Merge branch 'main' into bench/heap-read-store
fkrause98 Aug 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,82 @@ jobs:
working-directory: ${{ github.workspace }}
run: make bench

benchmark-run:
name: Run benchmarks
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Fetch submodules
run: make submodules

- name: Setup nodejs + yarn
uses: actions/setup-node@v4
with:
node-version: 18.20.2
cache-dependency-path: |
${{ github.workspace }}/zksync-era/contracts-test-data/yarn.lock
${{ github.workspace }}/zksync-era/contracts/l1-contracts/yarn.lock
${{ github.workspace }}/zksync-era/contracts/l2-contracts/yarn.lock
${{ github.workspace }}/zksync-era/contracts/system-contracts/yarn.lock

- name: Build benchmark contracts
if: steps.contracts-cache.outputs.cache-hit != 'true'
id: bench-setup
run: make bench-setup

- name: Fetch toolchain version from zksync-era
run: |
cd ${{ github.workspace }}/zksync-era
echo "ERA_TOOLCHAIN=$(head ./rust-toolchain)" >> $GITHUB_ENV

- name: Rustup toolchain install
uses: dtolnay/rust-toolchain@nightly
with:
toolchain: ${{ env.ERA_TOOLCHAIN }}

- uses: Swatinem/rust-cache@v2
with:
workspaces: |
era_vm/zksync-era/core/tests/vm-benchmark

- name: Zksync-era dependencies
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: clang clang-tools build-essential librocksdb-dev
version: 1.0

- name: Check benchmarks build
run: |
cd ${{ github.workspace }}/zksync-era
cargo build --benches

# Download previous benchmark result from cache (if exists)
- name: Download previous benchmark data
uses: actions/cache@v4
with:
path: ./cache
key: main-${{ runner.os }}-benchmark

# Run `github-action-benchmark` action
- name: Store benchmark result
uses: benchmark-action/github-action-benchmark@v1
with:
# What benchmark tool the output.txt came from
tool: 'cargo'
# Where the output from the benchmark tool is stored
output-file-path: "${{github.workspace}}/output.txt"
# Where the previous data file is stored
external-data-json-path: ./cache/benchmark-data.json
# Workflow will fail when an alert happens
fail-on-alert: true
# GitHub API token to make a commit comment
github-token: ${{ secrets.GITHUB_TOKEN }}
# Enable alert commit comment
comment-on-alert: true
# Enable Job Summary for PRs
summary-always: true

zksync_era_tests:
runs-on: ubuntu-latest
Expand Down
34 changes: 10 additions & 24 deletions src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,20 +415,15 @@ impl Heap {
}

pub fn store(&mut self, address: u32, value: U256) {
let mut bytes: [u8; 32] = [0; 32];
value.to_big_endian(&mut bytes);
for (i, item) in bytes.iter().enumerate() {
self.heap[address as usize + i] = *item;
}
let start = address as usize;
let end = start + 32;
value.to_big_endian(&mut self.heap[start..end]);
}

pub fn read(&self, address: u32) -> U256 {
let mut result = U256::zero();

for i in 0..32 {
result |= U256::from(self.heap[address as usize + (31 - i)]) << (i * 8);
}
result
let start = address as usize;
let end = start + 32;
U256::from_big_endian(&self.heap[start..end])
}

pub fn expanded_read(&mut self, address: u32) -> (U256, u32) {
Expand All @@ -445,24 +440,15 @@ impl Heap {
let mut result = U256::zero();
for i in 0..32 {
let addr = pointer.start + pointer.offset + (31 - i);
if addr < pointer.start + pointer.len {
result |= U256::from(self.heap[addr as usize]) << (i * 8);
}
result |= U256::from(self.heap[addr as usize]) << (i * 8);
}
result
}

pub fn read_unaligned_from_pointer(&self, pointer: &FatPointer) -> Result<Vec<u8>, HeapError> {
let mut result = Vec::new();
let start = pointer.start + pointer.offset;
let finish = start + pointer.len;
for i in start..finish {
if i as usize >= self.heap.len() {
return Err(HeapError::ReadOutOfBounds);
}
result.push(self.heap[i as usize]);
}
Ok(result)
let start = (pointer.start + pointer.offset) as usize;
let finish = (start + pointer.len as usize).min(self.heap.len());
Ok(self.heap[start..finish].into())
}

pub fn len(&self) -> usize {
Expand Down