Skip to content

Commit

Permalink
perf[venom]: add OrderedSet.last() (#4236)
Browse files Browse the repository at this point in the history
smidge performance improvement (roughly 3%). peek directly at end of
`OrderedSet` instead of converting to list every time.
  • Loading branch information
charles-cooper authored Sep 18, 2024
1 parent f7b8e93 commit 53f7675
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
with:
types: |
feat
perf
fix
chore
refactor
Expand Down
6 changes: 6 additions & 0 deletions vyper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def __repr__(self):
def __iter__(self):
return iter(self._data)

def __reversed__(self):
return reversed(self._data)

def __contains__(self, item):
return self._data.__contains__(item)

Expand All @@ -45,6 +48,9 @@ def __len__(self):
def first(self):
return next(iter(self))

def last(self):
return next(reversed(self))

def pop(self):
return self._data.popitem()[0]

Expand Down
3 changes: 1 addition & 2 deletions vyper/venom/venom_to_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,7 @@ def _generate_evm_for_instruction(
else:
# peek at next_liveness to find the next scheduled item,
# and optimistically swap with it
# TODO: implement OrderedSet.last()
next_scheduled = list(next_liveness)[-1]
next_scheduled = next_liveness.last()
self.swap_op(assembly, stack, next_scheduled)

return apply_line_numbers(inst, assembly)
Expand Down

0 comments on commit 53f7675

Please sign in to comment.