Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(data-modeling): speed up large DAG layout, fix table pagination (#73408)

Jovan Sakovic5af9879285de
diff --git a/frontend/src/scenes/data-warehouse/scene/modeling/TableView.tsx b/frontend/src/scenes/data-warehouse/scene/modeling/TableView.tsx
index b04bce93b7f3..ccf7ca7e01a4 100644
--- a/frontend/src/scenes/data-warehouse/scene/modeling/TableView.tsx
+++ b/frontend/src/scenes/data-warehouse/scene/modeling/TableView.tsx
@@ -48,7 +48,6 @@ export function TableView(): JSX.Element {
}
return (
<LemonTable
- className="h-[calc(100vh-17rem)] overflow-y-auto"
dataSource={visibleNodes}
loading={nodesLoading}
columns={[
diff --git a/frontend/src/scenes/data-warehouse/scene/modeling/autolayout.ts b/frontend/src/scenes/data-warehouse/scene/modeling/autolayout.ts
index 59bb850da466..77b62c6cd685 100644
--- a/frontend/src/scenes/data-warehouse/scene/modeling/autolayout.ts
+++ b/frontend/src/scenes/data-warehouse/scene/modeling/autolayout.ts
@@ -3,7 +3,7 @@ import type { ElkExtendedEdge, ElkNode } from 'elkjs/lib/elk.bundled.js'
import { getElk } from 'lib/elk'
-import { NODE_HEIGHT, NODE_WIDTH } from './constants'
+import { LARGE_GRAPH_NODE_THRESHOLD, NODE_HEIGHT, NODE_WIDTH } from './constants'
import type { ElkDirection, Node } from './types'
const getElkPortSide = (position: Position): string => {
@@ -25,6 +25,10 @@ export const getFormattedNodes = async (nodes: Node[], edges: Edge[], direction?
}
direction ??= 'DOWN'
+ // NETWORK_SIMPLEX node placement gives the tightest layout but scales
+ // super-linearly; on large graphs it's the main reason the DAG takes
+ // seconds to appear. BRANDES_KOEPF is ~5x cheaper with a comparable result.
+ const nodePlacementStrategy = nodes.length > LARGE_GRAPH_NODE_THRESHOLD ? 'BRANDES_KOEPF' : 'NETWORK_SIMPLEX'
const elkOptions = {
'elk.algorithm': 'layered',
'elk.direction': direction,
@@ -34,7 +38,7 @@ export const getFormattedNodes = async (nodes: Node[], edges: Edge[], direction?
'elk.layered.layering.strategy': 'NETWORK_SIMPLEX',
'elk.layered.mergeEdges': 'true',
'elk.layered.nodePlacement.bk.fixedAlignment': 'BALANCED',
- 'elk.layered.nodePlacement.strategy': 'NETWORK_SIMPLEX',
+ 'elk.layered.nodePlacement.strategy': nodePlacementStrategy,
'elk.layered.spacing.nodeNodeBetweenLayers': '60',
'elk.padding': '[left=0, top=0, right=0, bottom=0]',
'elk.separateConnectedComponents': 'true',
diff --git a/frontend/src/scenes/data-warehouse/scene/modeling/constants.ts b/frontend/src/scenes/data-warehouse/scene/modeling/constants.ts
index fda8f72f8655..26103858cd47 100644
--- a/frontend/src/scenes/data-warehouse/scene/modeling/constants.ts
+++ b/frontend/src/scenes/data-warehouse/scene/modeling/constants.ts
@@ -1,7 +1,13 @@
-export const PAGE_SIZE = 100
+export const PAGE_SIZE = 40
export const NODE_WIDTH = 180
export const NODE_HEIGHT = 120
+// Above this node count, ELK's NETWORK_SIMPLEX node placement (which scales
+// super-linearly and runs on the main thread) becomes the dominant cost of
+// showing the graph. We switch to the much cheaper BRANDES_KOEPF placement for
+// large graphs; smaller graphs keep NETWORK_SIMPLEX for its tighter layout.
+export const LARGE_GRAPH_NODE_THRESHOLD = 150
+
export const TOP_HANDLE_POSITION = {
x: NODE_WIDTH / 2,
y: 0,