Skip to content

Commit e91e65d

Browse files
committed
Renderers: Make appending rows massively more efficient
Previously we were generating the list of children (for most likely the root node) for every single append statement, during which we were recalculating the length of the list, twice. In plugins that output a lot of rows this would add an enourmous overhead (that likely grew as the length of the output grew). Without this overhead, the time taken for the TreeGrid._append method went from 1230.0s to 2.4s.
1 parent dd13b42 commit e91e65d

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

volatility3/framework/renderers/__init__.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,20 +272,26 @@ def values(self, node):
272272
def _append(self, parent: Optional[interfaces.renderers.TreeNode], values: Any) -> TreeNode:
273273
"""Adds a new node at the top level if parent is None, or under the
274274
parent node otherwise, after all other children."""
275-
children = self.children(parent)
276-
return self._insert(parent, len(children), values)
275+
return self._insert(parent, None, values)
277276

278-
def _insert(self, parent: Optional[interfaces.renderers.TreeNode], position: int, values: Any) -> TreeNode:
277+
def _insert(self, parent: Optional[interfaces.renderers.TreeNode], position: Optional[int], values: Any) -> TreeNode:
279278
"""Inserts an element into the tree at a specific position."""
280279
parent_path = ""
281280
children = self._find_children(parent)
282281
if parent is not None:
283282
parent_path = parent.path + self.path_sep
284-
newpath = parent_path + str(position)
283+
if position is None:
284+
newpath = parent_path + str(len(children))
285+
else:
286+
newpath = parent_path + str(position)
287+
for node, _ in children[position:]:
288+
self.visit(node, lambda child, _: child.path_changed(newpath, True), None)
289+
285290
tree_item = TreeNode(newpath, self, parent, values)
286-
for node, _ in children[position:]:
287-
self.visit(node, lambda child, _: child.path_changed(newpath, True), None)
288-
children.insert(position, (tree_item, []))
291+
if position is None:
292+
children.append((tree_item, []))
293+
else:
294+
children.insert(position, (tree_item, []))
289295
return tree_item
290296

291297
def is_ancestor(self, node, descendant):

0 commit comments

Comments
 (0)