跪拜 Guibai
← All articles
Frontend · Open Source · Data Visualization

Meta2d.js 2.0 Rewrites the 2D Visualization Engine for Million-Node Canvases and Built-In Collaboration

By alsmile ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Teams building SCADA, industrial dashboards, or canvas editors no longer need to hand-roll picking, partial redraws, or WebSocket sync; the engine ships those as built-ins under MIT, and its data-driven JSON model plugs directly into AI-generated visualization pipelines.

Summary

The open-source engine, aimed at industrial HMI/SCADA, monitoring dashboards, and diagram editors, has moved from a single-threaded full-canvas redraw model to a 1-main-thread-plus-4-Web-Worker design. Rendering, picking, interaction, and protocol handling now live in separate workers, so dragging, zooming, and animation leave the main thread at zero occupancy. The render thread uses OffscreenCanvas and partial repaints based on per-node bounding boxes, while a compute thread handles picking via an adaptive spatial grid that limits candidate nodes to at most 1,000 per cell.

Benchmarks show 10,000 nodes at 117–120 FPS with 44–50 MB memory, 100,000 nodes at 114–120 FPS with 80–110 MB, and 1,000,000 nodes at 109–117 FPS with 510–840 MB, with mouse picking holding frame rate at all levels. The rewrite also adds native GIF/APNG parsing in a worker thread, frame-level animation processing moved off the main thread, and multiplayer collaboration via delta patches that can be replayed for new room members.

The engine is designed to be AI-friendly: its core is a structured JSON data model, so AI-generated visualization data can render immediately, and AI agents can act as collaborators on the same canvas. The development team used Claude 5.5 and GPT-6 to perform deep performance optimization after the architectural rewrite, which delayed the release but produced better-than-expected results.

Takeaways
— Meta2d.js 2.0 renders 1,000,000 nodes at 109–117 FPS using 510–840 MB memory, 100,000 nodes at 114–120 FPS using 80–110 MB, and 10,000 nodes at 117–120 FPS using 44–50 MB, with mouse picking causing no frame drops.
— The engine architecture is 1 main thread plus 4 Web Workers: render (OffscreenCanvas), compute (picking, viewport clipping, dirty regions), interaction (state and hover), and tool (MQTT/WS/HTTP/SSE/SQL connections and GIF/APNG parsing).
— Picking uses an adaptive spatial grid; with fewer than 2,000 nodes the whole canvas is one cell, otherwise cells are sized so each contains at most about 1,000 candidate nodes.
— Partial repaint computes per-node bounding boxes and precomputed pen boundarys, so drag, hover, selection, and animation only clear and redraw dirty regions instead of the full canvas.
— GIF and APNG are parsed frame-level in the tool worker, outputting { imageBitmap, duration } sequences, with results batch-transferred every 50ms.
— Multiplayer collaboration uses delta patches identical to the engine's patch mechanism; new room members get a replay of historical deltas from the server, and accessToken acts as the room ID.
— The team used Claude 5.5 and GPT-6 to do deep performance optimization after the architecture was written, which delayed the release but improved performance beyond expectations.
— Meta2d.js 2.0 offers built-in data communication (MQTT/WebSocket/HTTP/SSE/SQL), conditional alarms, editor interactions, and collaboration, whereas Konva.js, Fabric.js, and PixiJS require assembling these features manually.
Conclusions

The decision to let AI audit and rewrite the render pipeline, after engineers had designed the architecture based on five years of experience, suggests that LLMs can now meaningfully optimize complex canvas codebases, but only when the underlying architecture is already sound.

By moving animation interpolation and picking into worker threads and using delta patches to sync collaboration, Meta2d.js 2.0 pushes the browser canvas model far beyond what typical 2D libraries offer, effectively making million-element editors a practical target for web applications.

The collaboration model treats AI agents as first-class participants in the same delta-patch stream as humans, which points toward a future where generative AI doesn't just produce static output but iterates live on shared canvas state.

Concepts & terms
Dirty rectangle / 脏区
A region of the canvas that changed since the last frame. Instead of clearing and redrawing the entire canvas, only these rectangles are cleared and repainted, cutting per-frame work dramatically.
Spatial grid index / 空间网格索引
A data structure that divides the canvas into a grid of cells. When picking a node at a given coordinate, only nodes inside the corresponding cell are tested, reducing hit-testing from O(N) to O(cell size).
Delta patch / 差量同步
A compact representation of changes between two states. In collaboration, patches describe only what changed on the canvas, so remote clients apply a single partial repaint and new joiners can replay the patch history to reconstruct the full state.
OffscreenCanvas
A browser API that allows rendering to a canvas in a Web Worker without touching the main thread. It enables drawing operations to happen off the UI thread, keeping the main thread free for input and layout.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗