Skip to content

🐛 Fix: Remove lag when copying and pasting nodes - #436

Merged
MFA-X-AI merged 4 commits into
XpressAI:masterfrom
rabea-al:fix/lag-on-copy-paste-nodes
Aug 14, 2025
Merged

MFA-X-AI merged 4 commits into
XpressAI:masterfrom
rabea-al:fix/lag-on-copy-paste-nodes

Conversation

@rabea-al

@rabea-al rabea-al commented Aug 11, 2025 •

Copy link
Copy Markdown
Contributor

Description

Cause of the issue:
Introduced in PR #424 — In xircuitsbodywidget, the line:
CustomPortModel.attachEngine(deserializedModel, engine);
caused noticeable lag during copy/paste because it iterated over all ports in the diagram after deserialization and reassigned the engine to them all at once.

What was done:

  • Replaced all showNodeCenteringNotification calls inside CustomPortModel.ts only with emitPortNotice.

  • Added a listener in the UI (XircuitsBodyWidget.tsx) using the useNodeNotice hook to receive events and call showNodeCenteringNotification with the current engine.

  • Prevent passing/storing the engine inside ports (caused previous lag/memory leak).

  • Filter notifications using modelId to ensure they appear only in the correct canvas when multiple tabs are open.

  • CustomPortModel now triggers emitPortNotice({ message, nodeId, modelId }) instead of direct calls.

  • In XircuitsBodyWidget.tsx, kept using showNodeCenteringNotification for places that already have an engine reference.

  • Left showNodeCenteringNotification calls in .tsx files that own the engine since this is safe and doesn't cause memory leaks.

Pull Request Type

  • Xircuits Core (Jupyterlab Related changes)
  • Xircuits Canvas (Custom RD Related changes)
  • Xircuits Component Library
  • Xircuits Project Template
  • Testing Automation
  • Documentation
  • Others (Please Specify)

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Tests

0. Performance Stress Test

  • Attempted to copy/paste a large number of nodes multiple times in a large workflow.
  • Expected: No noticeable lag or UI freeze after fix.

1. In-to-In Port Connection Check

  • Attempted to connect two InPorts together.
  • Notification: "Link cannot be created between inPorts."

2. Triangle Port Link Check

  • Tried connecting non-triangle port to triangle port.
  • Notification: "Flow ports (▶) can only connect to other flow ports (▶)."

3. Invalid Link Direction

  • Connected ports from left-to-right instead of right-to-left.
  • Notification: "Link should be created from an outPort to an inPort."

4. Data Type Mismatch

  • Linked ports with incompatible data types.
  • Notification includes expected vs. provided types.

5. InPort Already Connected

  • Tried connecting a second link to an InPort.
  • Notification: "You can only create one link for this inPort..."

6. Last Node is Not “Finish”

  • Workflow ends with wrong node.
  • Notification: "Please make sure this \"<name>\" node ends with a \"Finish\" node."

7. Unconnected ★ InPort

  • Tried compiling/running with missing [★] compulsory connections.
  • Notification: "Please make sure the [★]COMPULSORY InPorts are connected."

8. Component Path Error

  • Dropped a missing/invalid component.
  • Notification: "Component could not be loaded from path..."

Tested on? Specify Version.

  • Windows
  • Linux Fedora
  • Mac
  • Others (State here -> xxx )

@github-actions

Copy link
Copy Markdown

Binder 👈 Launch a binder notebook on branch rabea-al/xircuits/fix/lag-on-copy-paste-nodes

@rabea-al

Copy link
Copy Markdown
Contributor Author
  • Replaced all showNodeCenteringNotification calls inside CustomPortModel.ts only with emitPortNotice.

  • Added a listener in the UI (XircuitsBodyWidget.tsx) using the useNodeNotice hook to receive events and call showNodeCenteringNotification with the current engine.

  • Prevent passing/storing the engine inside ports (caused previous lag/memory leak).

  • Filter notifications using modelId to ensure they appear only in the correct canvas when multiple tabs are open.

  • CustomPortModel now triggers emitPortNotice({ message, nodeId, modelId }) instead of direct calls.

  • In XircuitsBodyWidget.tsx, kept using showNodeCenteringNotification for places that already have an engine reference.

  • Left showNodeCenteringNotification calls in .tsx files that own the engine since this is safe and doesn't cause memory leaks.

Comment thread src/components/port/CustomPortModel.ts Resolved

@MFA-X-AI MFA-X-AI left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Other than the short comment, it does seem to be working.
I was worried that

const getEngine = useCallback(() => xircuitsApp.getDiagramEngine(), [xircuitsApp]);
  	useNodeNotice(getEngine);

this implementation could be triggered on every render, but it properly only triggers on notification errors. I confirm that the other notifications spawns properly too.

So aside from that small case update, could you also update the outdated main PR message to reflect the changes? Just copy paste the comment you've made after the requested fixes.

@rabea-al

Copy link
Copy Markdown
Contributor Author

Thanks for the review!
I’ve renamed cur to currentParent and pushed the change.
I’ve also updated the main PR description to reflect the final approach.

@rabea-al
rabea-al marked this pull request as ready for review August 13, 2025 03:08

@MFA-X-AI MFA-X-AI left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM! Good job.

@MFA-X-AI
MFA-X-AI merged commit 1245bb2 into XpressAI:master Aug 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants