-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tree: various speedups #887
base: main
Are you sure you want to change the base?
Conversation
1ff3d54
to
fab2410
Compare
loopy/schedule/tree.py
Outdated
@dataclass(frozen=True) | ||
# Not frozen because it is slower. Tree objects are immutable, and offer no | ||
# way to mutate the tree. | ||
@dataclass(frozen=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dataclass(frozen=False) | |
@dataclass(frozen=__debug__) |
(And adapt the comment suitably?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$ ./run-mypy.sh
loopy/schedule/tree.py:55: error: "frozen" argument must be a True or False literal [literal-required]
🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
loopy/schedule/tree.py
Outdated
def is_root(self, node: NodeT) -> bool: | ||
assert node in self | ||
# cast-reason: parent_of_node can not be None (as per is_root check) | ||
return 1 + self.depth(cast(NodeT, parent_of_node)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use not_none
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, wouldn't it be easier just to leave the assert there, instead of the not_none
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would something like this work?
parent_of_node = self.parent(node)
if parent_of_node is None:
return 0
return 1 + self.depth(parent_of_node)
No need to hide the None check in another function (which tricks mypy) + this only does the parent lookup once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds good, thanks! cdc3235
What's the performance impact with/without when using |
I added a table in the first comment that compares with |
The mypy failures are probably due to inducer/cgen#50 (which adds |
- make dataclass non-frozen - use mutate() for cases where a Map is modified multiple times - remove asserts for cases that would fail immediately anyway
Co-authored-by: Alexandru Fikl <[email protected]>
25c6c08
to
9726d9b
Compare
For the following microbenchmark:
, this PR results in performance improvements: