Skip to content

Conversation

@charles-cooper
Copy link
Member

@charles-cooper charles-cooper commented Sep 19, 2024

What I did

reduces branch_storm.vy from 1007 bytes to 754 bytes(!)

a "million dollar pen" (https://en.wikipedia.org/wiki/Space_Pen).

How I did it

only do stack reorder before join points.

How to verify it

Commit message

fix a venom performance bug, where the stack would be reordered before
all jump instructions.

for "joining" jump instructions (where the target basic block can have
multiple cfg inputs), the stack reorder is needed, since we need the
invariant that the stack layout needs to be the same no matter which
basic block we jump to the target basic block from.

however, before jumping into a block with only a single `cfg_in`
(which, after cfg normalization, is equivalent to "splitting" jump
instructions `jnz` and `djmp`), the stack reorder is unneeded, since
stack reordering happens anyways in the target basic block, and no
invariant on the incoming stack layout is required.

this commit changes the behavior so that stack reordering only occurs
before these "joining" jump instructions.

on branch-heavy code, this can improve codesize by as much as 25%, with
corresponding gas improvement, especially in the presence of loops.

Description for the changelog

Cute Animal Picture

image

@charles-cooper charles-cooper changed the title feat[venom]: a million dollar pen feat[venom]: only stack_reorder before join points Sep 19, 2024
@charles-cooper charles-cooper enabled auto-merge (squash) September 20, 2024 14:14
@charles-cooper charles-cooper merged commit 48a5da4 into vyperlang:master Sep 20, 2024
charles-cooper added a commit to charles-cooper/vyper that referenced this pull request Oct 5, 2024
fix a venom performance bug, where the stack would be reordered before
all jump instructions.

for "joining" jump instructions (where the target basic block can have
multiple cfg inputs), the stack reorder is needed, since we need the
invariant that the stack layout needs to be the same no matter which
basic block we jump to the target basic block from.

however, before jumping into a block with only a single `cfg_in`
(which, after cfg normalization, is equivalent to "splitting" jump
instructions `jnz` and `djmp`), the stack reorder is unneeded, since
stack reordering happens anyways in the target basic block, and no
invariant on the incoming stack layout is required.

this commit changes the behavior so that stack reordering only occurs
before these "joining" jump instructions.

on branch-heavy code, this can improve codesize by as much as 25%, with
corresponding gas improvement, especially in the presence of loops.
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.

3 participants