Skip to content
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

perf(ir): avoid exponential growth on name attribute access #8445

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ibis/expr/operations/core.py
Original file line number Diff line number Diff line change
@@ -85,7 +85,11 @@ def __coerce__(
# TODO(kszucs): figure out how to represent not named arguments
@property
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should turn this into @attribute in a follow-up since the .name property is accessed multiple times during both construction and compilation.

def name(self) -> str:
names = (arg.name for arg in self.__args__ if hasattr(arg, "name"))
names = (
name
for arg in self.__args__
if (name := getattr(arg, "name", None)) is not None
)
return f"{self.__class__.__name__}({', '.join(names)})"

@property
9 changes: 9 additions & 0 deletions ibis/expr/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -147,3 +147,12 @@ def test_implicit_coercion_of_null_literal(op):

assert expr1.op() == expected
assert expr2.op() == expected


def test_nested_name_property():
x = ibis.literal(1)
n = 100
for _ in range(n): # noqa: F402
x = x + 1

assert x.op().name.count("Add") == n
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cpcloud do we want to add some way of checking for recursion explosion? Maybe use n=200 and then test this doesn't take longer than 3 seconds to compute?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It didn't finish in any reasonable amount of time, so just having it as a standard unit test seems fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh, I see, so you would just notice it during local dev, no automation needed. Sure that works.

Loading