Skip to content

Optimize execution loop #293

Merged
0xkarmacoma merged 13 commits intomainfrom
insn-cache
May 23, 2024
Merged

Optimize execution loop #293
0xkarmacoma merged 13 commits intomainfrom
insn-cache

Conversation

@0xkarmacoma
Copy link
Copy Markdown
Contributor

Completely driven by flamegraphs, I kept squeezing until the fetch-decode-execute loop almost disappeared from flamegraphs (now dominated by other things like calls to resolve_address_alias):

Tested on morpho blue, 24.8% faster:

before: check_fee(bytes4,address) (paths: 38, time: 21.82s (paths: 21.82s, models: 0.00s), bounds: [])
after:  check_fee(bytes4,address) (paths: 39, time: 16.41s (paths: 16.41s, models: 0.00s), bounds: [])

Avoids duplicating work:

  • load pgm[pc] to know the current instruction (doing a chunk lookup + indexing in the code bytevec)
  • load pgm[pc+1:pc+1+operand_size] for PUSHn instructions (every time it is executed, which can be expensive)
  • load pgm[pc] again to know the next_pc

Instead we do this eagerly once and then remember the result.

Plus some extra goodies:

  • support for MCOPY
  • explicit Message.call_scheme, which caused us to render deploy output in traces at high verbosity when the intent was to just display the number of bytes

Tested on morpho blue, 24.8% faster:

    before: check_fee(bytes4,address) (paths: 38, time: 21.82s (paths: 21.82s, models: 0.00s), bounds: [])
    after:  check_fee(bytes4,address) (paths: 39, time: 16.41s (paths: 16.41s, models: 0.00s), bounds: [])

Avoids duplicating work:

- load pgm[pc] to know the current instruction (doing a chunk lookup + indexing in the code bytevec)
- load pgm[pc+1:pc+1+operand_size] for PUSHn instructions (every time it is executed, which can be expensive)
- load pgm[pc] again to know the next_pc

Instead we do this eagerly once and then remember the result.
@0xkarmacoma 0xkarmacoma requested a review from daejunpark May 22, 2024 01:03
@0xkarmacoma
Copy link
Copy Markdown
Contributor Author

Tested on Farcaster, 11% faster:

# before
[PASS] check_Invariants_PostMigration(bytes4,address) (paths: 641, time: 195.43s (paths: 195.43s, models: 0.00s), bounds: [])

# after
[PASS] check_Invariants_PostMigration(bytes4,address) (paths: 637, time: 173.95s (paths: 173.95s, models: 0.00s), bounds: [])

@0xkarmacoma 0xkarmacoma merged commit 337adba into main May 23, 2024
@0xkarmacoma 0xkarmacoma deleted the insn-cache branch May 23, 2024 00:49
pcaversaccio added a commit to pcaversaccio/snekmate that referenced this pull request Jun 18, 2025
### 🕓 Changelog

This commit updates the version `pragma`s in all 🐍Vyper source files to
target the latest `master` version `0.4.3rc2`, aligning with the release
of Vyper's newest release candidate version
[`0.4.3rc1`](https://github.com/vyperlang/vyper/releases/tag/v0.4.3rc1).
Furthermore, all 🐍 snekmate contracts now target the new 🐍Vyper [default
EVM version](vyperlang/vyper#4633) `prague`.
Also, we now target the `prague` EVM version for all `halmos`-based
tests, as the previously missing opcodes `MCOPY`, `TLOAD`, and `TSTORE`
have been added via
[a16z/halmos#293](a16z/halmos#293) and
[a16z/halmos#463](a16z/halmos#463). Eventually,
all submodules have been updated to their most recent commits.

---------

Signed-off-by: Pascal Marco Caversaccio <[email protected]>
willbrown84 added a commit to willbrown84/snekmate that referenced this pull request Sep 23, 2025
### 🕓 Changelog

This commit updates the version `pragma`s in all 🐍Vyper source files to
target the latest `master` version `0.4.3rc2`, aligning with the release
of Vyper's newest release candidate version
[`0.4.3rc1`](https://github.com/vyperlang/vyper/releases/tag/v0.4.3rc1).
Furthermore, all 🐍 snekmate contracts now target the new 🐍Vyper [default
EVM version](vyperlang/vyper#4633) `prague`.
Also, we now target the `prague` EVM version for all `halmos`-based
tests, as the previously missing opcodes `MCOPY`, `TLOAD`, and `TSTORE`
have been added via
[a16z/halmos#293](a16z/halmos#293) and
[a16z/halmos#463](a16z/halmos#463). Eventually,
all submodules have been updated to their most recent commits.

---------

Signed-off-by: Pascal Marco Caversaccio <[email protected]>
void-rider5560p added a commit to void-rider5560p/snekmate that referenced this pull request Sep 28, 2025
### 🕓 Changelog

This commit updates the version `pragma`s in all 🐍Vyper source files to
target the latest `master` version `0.4.3rc2`, aligning with the release
of Vyper's newest release candidate version
[`0.4.3rc1`](https://github.com/vyperlang/vyper/releases/tag/v0.4.3rc1).
Furthermore, all 🐍 snekmate contracts now target the new 🐍Vyper [default
EVM version](vyperlang/vyper#4633) `prague`.
Also, we now target the `prague` EVM version for all `halmos`-based
tests, as the previously missing opcodes `MCOPY`, `TLOAD`, and `TSTORE`
have been added via
[a16z/halmos#293](a16z/halmos#293) and
[a16z/halmos#463](a16z/halmos#463). Eventually,
all submodules have been updated to their most recent commits.

---------

Signed-off-by: Pascal Marco Caversaccio <[email protected]>
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.

2 participants