From 4ecd26b3651fd3069cfd65055d654afb8e9d554c Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Wed, 7 Feb 2024 04:34:16 -0800 Subject: [PATCH] perf: reimplement `IRnode.__deepcopy__` (#3761) `deepcopy` is a hotspot for compile time. this commit results in a 16% improvement in compile time. --- vyper/codegen/ir_node.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/vyper/codegen/ir_node.py b/vyper/codegen/ir_node.py index 45d93f3067..b1a71021c8 100644 --- a/vyper/codegen/ir_node.py +++ b/vyper/codegen/ir_node.py @@ -1,4 +1,5 @@ import contextlib +import copy import re from enum import Enum, auto from functools import cached_property @@ -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):