Skip to content

Commit

Permalink
perf: reimplement IRnode.__deepcopy__ (vyperlang#3761)
Browse files Browse the repository at this point in the history
`deepcopy` is a hotspot for compile time. this commit results in a 16%
improvement in compile time.
  • Loading branch information
charles-cooper authored Feb 7, 2024
1 parent e20885e commit 4ecd26b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions vyper/codegen/ir_node.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import contextlib
import copy
import re
from enum import Enum, auto
from functools import cached_property
Expand Down Expand Up @@ -392,6 +393,14 @@ def __init__(
raise CompilerPanic(f"Invalid value for IR AST node: {self.value}")
assert isinstance(self.args, list)

# deepcopy is a perf hotspot; it pays to optimize it a little
def __deepcopy__(self, memo):
cls = self.__class__
ret = cls.__new__(cls)
ret.__dict__ = self.__dict__.copy()
ret.args = [copy.deepcopy(arg) for arg in ret.args]
return ret

# TODO would be nice to rename to `gas_estimate` or `gas_bound`
@property
def gas(self):
Expand Down

0 comments on commit 4ecd26b

Please sign in to comment.