From 2d2a68224296342b3c888676848d7da9dc0b1cce Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Fri, 16 Feb 2024 14:43:48 -0800 Subject: [PATCH] feat: optimize `VyperNode.__deepcopy__` (#3784) `VyperNode.__deepcopy__` is a hotspot in the frontend. this commit improves time spent in the frontend by 10% --- vyper/ast/nodes.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vyper/ast/nodes.py b/vyper/ast/nodes.py index fb5fb73592..0ebe18ab5d 100644 --- a/vyper/ast/nodes.py +++ b/vyper/ast/nodes.py @@ -4,6 +4,7 @@ import decimal import functools import operator +import pickle import sys import warnings from typing import Any, Optional, Union @@ -357,6 +358,9 @@ def __hash__(self): values = [getattr(self, i, None) for i in VyperNode.__slots__ if not i.startswith("_")] return hash(tuple(values)) + def __deepcopy__(self, memo): + return pickle.loads(pickle.dumps(self)) + def __eq__(self, other): if not isinstance(other, type(self)): return False @@ -786,7 +790,6 @@ class ExprNode(VyperNode): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self._expr_info = None