-
Notifications
You must be signed in to change notification settings - Fork 17
Runtime improvement for pseudo op extension #617
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -159,18 +159,48 @@ def inject_pseudo_op_wrap_children( | |||||||||||||||||||||||||||||||||||||||||
| parent_evt["children"] = [pseudo_evt["UID"]] | ||||||||||||||||||||||||||||||||||||||||||
| pseudo_evt["parent"] = parent_evt["UID"] | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # Descendants that were cpu_root_nodes are no longer roots since they | ||||||||||||||||||||||||||||||||||||||||||
| # now live under the pseudo op. Remove them and promote the pseudo op. | ||||||||||||||||||||||||||||||||||||||||||
| root_set = set(tree.cpu_root_nodes) | ||||||||||||||||||||||||||||||||||||||||||
| # Descendants that were cpu_root_nodes are no longer roots since they now | ||||||||||||||||||||||||||||||||||||||||||
| # live under the pseudo op. Removals/additions are accumulated into per-tree | ||||||||||||||||||||||||||||||||||||||||||
| # pending sets and callers MUST invoke ``finalize_pseudo_op_mutations(tree)`` after the | ||||||||||||||||||||||||||||||||||||||||||
| # last call to commit the accumulated changes back to ``tree.cpu_root_nodes``. | ||||||||||||||||||||||||||||||||||||||||||
| pending_removals = getattr(tree, "_cpu_root_nodes_pending_removals", None) | ||||||||||||||||||||||||||||||||||||||||||
| if pending_removals is None: | ||||||||||||||||||||||||||||||||||||||||||
| pending_removals = set() | ||||||||||||||||||||||||||||||||||||||||||
| tree._cpu_root_nodes_pending_removals = pending_removals | ||||||||||||||||||||||||||||||||||||||||||
| tree._cpu_root_nodes_pending_additions = [] | ||||||||||||||||||||||||||||||||||||||||||
| tree._cpu_root_nodes_set = set(tree.cpu_root_nodes) | ||||||||||||||||||||||||||||||||||||||||||
| pending_additions = tree._cpu_root_nodes_pending_additions | ||||||||||||||||||||||||||||||||||||||||||
| root_set = tree._cpu_root_nodes_set | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| stack = list(children_uids) | ||||||||||||||||||||||||||||||||||||||||||
| while stack: | ||||||||||||||||||||||||||||||||||||||||||
| uid = stack.pop() | ||||||||||||||||||||||||||||||||||||||||||
| if uid in root_set: | ||||||||||||||||||||||||||||||||||||||||||
| tree.cpu_root_nodes.remove(uid) | ||||||||||||||||||||||||||||||||||||||||||
| pending_removals.add(uid) | ||||||||||||||||||||||||||||||||||||||||||
| root_set.discard(uid) | ||||||||||||||||||||||||||||||||||||||||||
| evt = tree.get_UID2event(uid) | ||||||||||||||||||||||||||||||||||||||||||
| stack.extend(evt.get("children", [])) | ||||||||||||||||||||||||||||||||||||||||||
| tree.cpu_root_nodes.append(pseudo_evt["UID"]) | ||||||||||||||||||||||||||||||||||||||||||
| pending_additions.append(pseudo_evt["UID"]) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| def finalize_pseudo_op_mutations(tree): | ||||||||||||||||||||||||||||||||||||||||||
| """Commit any pending cpu_root_nodes mutations from | ||||||||||||||||||||||||||||||||||||||||||
| ``inject_pseudo_op_wrap_children`` back to ``tree.cpu_root_nodes`` | ||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||
| pending_removals = getattr(tree, "_cpu_root_nodes_pending_removals", None) | ||||||||||||||||||||||||||||||||||||||||||
| if pending_removals is None: | ||||||||||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||||||||||
| pending_additions = tree._cpu_root_nodes_pending_additions | ||||||||||||||||||||||||||||||||||||||||||
| if pending_removals: | ||||||||||||||||||||||||||||||||||||||||||
| tree.cpu_root_nodes = [ | ||||||||||||||||||||||||||||||||||||||||||
| u for u in tree.cpu_root_nodes if u not in pending_removals | ||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||
| if pending_additions: | ||||||||||||||||||||||||||||||||||||||||||
| tree.cpu_root_nodes.extend(pending_additions) | ||||||||||||||||||||||||||||||||||||||||||
| del tree._cpu_root_nodes_pending_removals | ||||||||||||||||||||||||||||||||||||||||||
| del tree._cpu_root_nodes_pending_additions | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+193
to
+201
|
||||||||||||||||||||||||||||||||||||||||||
| pending_additions = tree._cpu_root_nodes_pending_additions | |
| if pending_removals: | |
| tree.cpu_root_nodes = [ | |
| u for u in tree.cpu_root_nodes if u not in pending_removals | |
| ] | |
| if pending_additions: | |
| tree.cpu_root_nodes.extend(pending_additions) | |
| del tree._cpu_root_nodes_pending_removals | |
| del tree._cpu_root_nodes_pending_additions | |
| pending_additions = getattr(tree, "_cpu_root_nodes_pending_additions", []) | |
| if pending_removals: | |
| tree.cpu_root_nodes = [ | |
| u for u in tree.cpu_root_nodes if u not in pending_removals | |
| ] | |
| if pending_additions: | |
| tree.cpu_root_nodes.extend(pending_additions) | |
| if hasattr(tree, "_cpu_root_nodes_pending_removals"): | |
| del tree._cpu_root_nodes_pending_removals | |
| if hasattr(tree, "_cpu_root_nodes_pending_additions"): | |
| del tree._cpu_root_nodes_pending_additions |
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.
The pending-root tracking doesn’t account for pseudo-ops added during the current pending-mutation window. Because
root_setis only initialized from the originaltree.cpu_root_nodesand never updated withpseudo_evt['UID'], a subsequentinject_pseudo_op_wrap_childrenthat wraps a subtree containing an earlier pseudo-op will fail to mark that earlier pseudo-op for removal (the old eager implementation would remove it). Additionally, if you do add pseudo UIDs intoroot_set, ensure removals take precedence over additions (e.g., filterpending_additionsagainstpending_removalsinfinalize_pseudo_op_mutations).