Skip to content

Commit

Permalink
Cache result of row in _Node
Browse files Browse the repository at this point in the history
row() used a significant amount of time when profiling
  • Loading branch information
JHolba committed Jul 8, 2024
1 parent 9ac8a33 commit 6ad5642
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/ert/gui/model/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class _Node(ABC):
children: dict[int, IterNode | RealNode | ForwardModelStepNode] = field(
default_factory=dict
)
_index: Optional[int] = None

def __repr__(self) -> str:
parent = "no " if self.parent is None else ""
Expand All @@ -30,9 +31,12 @@ def add_child(
pass

def row(self) -> int:
if self.parent:
return list(self.parent.children.keys()).index(self.id_)
raise ValueError(f"{self} had no parent")
if not self._index:
if self.parent:
self._index = list(self.parent.children.keys()).index(self.id_)
else:
raise ValueError(f"{self} had no parent")
return self._index


@dataclass
Expand Down

0 comments on commit 6ad5642

Please sign in to comment.