Skip to content

Commit

Permalink
perf(ir): avoid exponential growth on name attribute access (#8445)
Browse files Browse the repository at this point in the history
Fixes #8432. In short, the pattern we are using here for accessing
`name` results in exponential growth of attribute accesses.
  • Loading branch information
cpcloud authored Feb 26, 2024
1 parent a755315 commit 7667328
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ibis/expr/operations/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ def __coerce__(
# TODO(kszucs): figure out how to represent not named arguments
@property
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
Expand Down
9 changes: 9 additions & 0 deletions ibis/expr/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7667328

Please sign in to comment.