Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Sep 30, 2024
1 parent e21f3e8 commit 6fc0bd8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
16 changes: 8 additions & 8 deletions vyper/ast/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,23 +331,23 @@ def get_fields(cls) -> set:
slot_fields = [x for i in cls.__mro__ for x in getattr(i, "__slots__", [])]
return set(i for i in slot_fields if not i.startswith("_"))

def __hash__(self):
values = [getattr(self, i, None) for i in VyperNode._public_slots]
return hash(tuple(values))

def __deepcopy__(self, memo):
# default implementation of deepcopy is a hotspot
return pickle.loads(pickle.dumps(self))

def __eq__(self, other):
# CMC 2024-03-03 I'm not sure it makes much sense to compare AST
# nodes, especially if they come from other modules
# useful for testing
def deepequals(self, other):
if not isinstance(other, type(self)):
return False
if getattr(other, "node_id", None) != getattr(self, "node_id", None):
return False
for field_name in (i for i in self.get_fields() if i not in VyperNode.__slots__):
if getattr(self, field_name, None) != getattr(other, field_name, None):
lhs = getattr(self, field_name, None)
rhs = getattr(other, field_name, None)
if isinstance(lhs, VyperNode):
if not lhs.deeqequals(rhs):
return False
elif lhs != rhs:
return False
return True

Expand Down
3 changes: 3 additions & 0 deletions vyper/cli/vyper_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ def compile_files(

ret[file_path] = output

if vyper.utils._profile is not None: # pragma: nocover
vyper.utils._profile.print_stats("time")

return ret


Expand Down
21 changes: 16 additions & 5 deletions vyper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,12 +516,23 @@ def timeit(msg):
print(f"{msg}: Took {total_time:.4f} seconds")


_profile = None


@contextlib.contextmanager
def timer(msg):
t0 = time.time()
yield
t1 = time.time()
print(f"{msg} took {t1 - t0}s")
def profile():
from cProfile import Profile

global _profile
if _profile is None:
_profile = Profile()
_profile.disable()

try:
_profile.enable()
yield
finally:
_profile.disable()


def annotate_source_code(
Expand Down

0 comments on commit 6fc0bd8

Please sign in to comment.