-
-
Notifications
You must be signed in to change notification settings - Fork 86
Performance Refactors #396
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
Open
amcdnl
wants to merge
7
commits into
master
Choose a base branch
from
edge-refactor-2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cff759d
update ignore
amcdnl e639cdb
improve layout
amcdnl c44a82d
good baseline
amcdnl f9f8264
ignore nul
amcdnl 9748ede
Add web worker support for layout calculations
amcdnl 6bca922
Add instanced node rendering for improved performance
amcdnl b8347aa
Address PR review feedback for node batching
amcdnl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,3 +69,6 @@ src/**/*.css.d.ts | |
|
|
||
| # IDE | ||
| .idea | ||
| /.claude/settings.local.json | ||
| .playwright-mcp/ | ||
| /nul | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /** | ||
| * Layout adapter that reads positions directly from graphology node attributes. | ||
| * Used when a worker (like FA2Layout) has already computed positions | ||
| * and stored them as x/y attributes on the graph nodes. | ||
| */ | ||
|
|
||
| import type Graph from 'graphology'; | ||
| import type { DragReferences } from '../store'; | ||
| import type { InternalGraphPosition, InternalVector3 } from '../types'; | ||
| import type { LayoutStrategy } from './types'; | ||
|
|
||
| export interface GraphPositionAdapterOptions { | ||
| graph: Graph; | ||
| drags?: DragReferences; | ||
| /** Whether the layout is 3D (reads z attribute) */ | ||
| is3d?: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * Creates a LayoutStrategy adapter that reads positions from graph node attributes. | ||
| * This allows using `transformGraph` instead of `transformGraphWithPositions` | ||
| * when positions are stored directly on the graph (e.g., from FA2 worker). | ||
| */ | ||
| export function createGraphPositionAdapter({ | ||
| graph, | ||
| drags, | ||
| is3d = false | ||
| }: GraphPositionAdapterOptions): LayoutStrategy { | ||
| return { | ||
| getNodePosition(id: string): InternalGraphPosition { | ||
| // Check for drag position first | ||
| if (drags?.[id]?.position) { | ||
| const dragPos = drags[id].position; | ||
| return { | ||
| x: dragPos.x, | ||
| y: dragPos.y, | ||
| z: dragPos.z ?? (is3d ? 0 : 1) | ||
| } as InternalGraphPosition; | ||
| } | ||
|
|
||
| // Read position from graph node attributes | ||
| const attrs = graph.getNodeAttributes(id); | ||
| return { | ||
| x: (attrs as any).x ?? 0, | ||
| y: (attrs as any).y ?? 0, | ||
| z: is3d ? ((attrs as any).z ?? 0) : 1 | ||
| } as InternalGraphPosition; | ||
| }, | ||
|
|
||
| // No-op step since the worker already ran the layout | ||
| step(): boolean { | ||
| return false; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Creates a LayoutStrategy adapter from a pre-computed positions Map. | ||
| * Used when positions come from a custom worker that returns a Map. | ||
| */ | ||
| export function createPositionMapAdapter( | ||
| positions: Map<string, InternalVector3>, | ||
| drags?: DragReferences, | ||
| is3d = false | ||
| ): LayoutStrategy { | ||
| return { | ||
| getNodePosition(id: string): InternalGraphPosition { | ||
| // Check for drag position first | ||
| if (drags?.[id]?.position) { | ||
| const dragPos = drags[id].position; | ||
| return { | ||
| x: dragPos.x, | ||
| y: dragPos.y, | ||
| z: dragPos.z ?? (is3d ? 0 : 1) | ||
| } as InternalGraphPosition; | ||
| } | ||
|
|
||
| // Read position from positions map | ||
| const pos = positions.get(id); | ||
| return { | ||
| x: pos?.x ?? 0, | ||
| y: pos?.y ?? 0, | ||
| z: is3d ? (pos?.z ?? 0) : 1 | ||
| } as InternalGraphPosition; | ||
| }, | ||
|
|
||
| // No-op step since the worker already ran the layout | ||
| step(): boolean { | ||
| return false; | ||
| } | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,13 +7,18 @@ | |
| * Promise based tick helper. | ||
| */ | ||
| export function tick(layout: LayoutStrategy) { | ||
| return new Promise((resolve, _reject) => { | ||
| return new Promise(async (resolve, _reject) => { | ||
| let stable: boolean | undefined; | ||
|
|
||
| function run() { | ||
| async function run() { | ||
| if (!stable) { | ||
| stable = layout.step(); | ||
| run(); | ||
| stable = await layout.step(); | ||
| if (!stable) { | ||
| // Use requestAnimationFrame for better performance in async scenarios | ||
| requestAnimationFrame(run); | ||
| } else { | ||
| resolve(stable); | ||
| } | ||
| } else { | ||
|
Comment on lines
+13
to
22
|
||
| resolve(stable); | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
antipattern here, should be synchronous ... if
layout.step()below throws, errors may no be caught properly and unhandled promise rejections can crash node (or show console errors/warnings at the very least)