performance

GitHub

提供Lichtblick代码库的性能优化指南,涵盖Chrome DevTools剖析流程、常见瓶颈(消息处理、渲染、内存)及零拷贝、对象池等优化模式。

.github/skills/performance/SKILL.md lichtblick-suite/lichtblick

Trigger Scenarios

性能分析与调优 解决卡顿或帧率问题 内存泄漏排查 实时数据可视化性能优化

Install

npx skills add lichtblick-suite/lichtblick --skill performance -g -y
More Options

Non-standard path

npx skills add https://github.com/lichtblick-suite/lichtblick/tree/develop/.github/skills/performance -g -y

Use without installing

npx skills use lichtblick-suite/lichtblick@performance

指定 Agent (Claude Code)

npx skills add lichtblick-suite/lichtblick --skill performance -a claude-code -g -y

安装 repo 全部 skill

npx skills add lichtblick-suite/lichtblick --all -g -y

预览 repo 内 skill

npx skills add lichtblick-suite/lichtblick --list

SKILL.md

Frontmatter
{
    "name": "performance",
    "description": "Deep performance optimization knowledge for the Lichtblick codebase. Covers profiling techniques, common bottlenecks, memory management patterns, and optimization strategies specific to real-time data visualization."
}

Performance Skill

Profiling Workflow

Chrome DevTools

  1. Performance tab: Record during playback, look for long tasks (>50ms)
  2. Memory tab: Take heap snapshots before/after operations, check for leaks
  3. Performance Monitor: Watch JS heap size, DOM nodes, layouts/sec in real-time
  4. Layers panel: Identify unnecessary compositing layers (GPU memory)

Key Metrics

  • Frame budget: 16.6ms at 60fps — anything longer causes jank
  • Tick budget: IterablePlayer caps at 300ms per tick
  • GC pressure: Frequent minor GCs indicate excessive allocation
  • Transfer size: Transferable objects (ArrayBuffer) should use zero-copy transfer

Common Bottlenecks

1. Message Processing (Player → Pipeline)

  • Symptom: Dropped frames during high-rate playback
  • Cause: Too many messages per tick, deserialization cost
  • Fix: Batch processing, Worker-based deserialization, subscription filtering

2. Render State Building (Pipeline → Panel)

  • Symptom: All panels re-render even when their data hasn't changed
  • Cause: Missing memoization in renderState.ts, non-stable references
  • Fix: Ensure buildRenderState returns same reference when data unchanged

3. 3D Scene Updates (Panel rendering)

  • Symptom: Low FPS in 3D panel with many objects
  • Cause: Per-frame geometry creation, excessive draw calls
  • Fix: DynamicBufferGeometry reuse, instanced rendering, frustum culling

4. Chart Rendering (Plot panel)

  • Symptom: Plot panel laggy with many data points
  • Cause: Chart.js processing 50k+ points on main thread
  • Fix: Worker-based dataset building (50k cap per series), OffscreenCanvas

5. Memory Pressure (Caching)

  • Symptom: Browser tab crashes or becomes unresponsive
  • Cause: Cache exceeds budget, large messages retained
  • Fix: Respect the 600MB player-level message cache budget (CachingIterableSource), evict behind read head, lazy deserialization. Note: this is separate from the 500MB default HTTP-layer cache in RemoteFileReadable/CachedFilelike used for remote file reads.

Optimization Patterns

Zero-Copy Transfer

// Transfer ArrayBuffer to Worker (not copy)
Comlink.transfer({ buffer: myArrayBuffer }, [myArrayBuffer]);
// After transfer, myArrayBuffer.byteLength === 0 (detached)

Object Pooling (3D)

// Reuse Vector3 instances instead of creating new ones
const tempVec = new THREE.Vector3();
function updatePosition(x: number, y: number, z: number) {
  tempVec.set(x, y, z);
  mesh.position.copy(tempVec);
}

Structural Sharing (State)

// Only create new object if data actually changed
const newMessages = messages !== prevMessages ? [...messages, ...newBatch] : prevMessages;

Debounced Emission

// Coalesce rapid state updates
#scheduleEmit() {
  if (this.#emitScheduled) return;
  this.#emitScheduled = true;
  queueMicrotask(() => {
    this.#emitScheduled = false;
    this.#emitStateImpl();
  });
}

Subscription Filtering

// Only request data for topics panels actually need
const activeTopics = mergeSubscriptions(allPanelSubscriptions);
player.setSubscriptions(activeTopics); // Player only iterates these

Memory Management

Identifying Leaks

  1. Take heap snapshot A (baseline)
  2. Perform operation (open/close panel, play/seek)
  3. Force GC (DevTools → Memory → Collect garbage)
  4. Take heap snapshot B
  5. Compare: Objects in B not in A = potential leaks

Common Leak Sources

  • Unremoved event listeners (especially on window or document)
  • Unreleased Comlink proxies (Worker not disposed)
  • Retained message references in closed panels
  • Subscription callbacks not unsubscribed on unmount

Prevention

  • FinalizationRegistry for Worker proxy cleanup (see ComlinkWrap)
  • useEffect cleanup functions for all subscriptions
  • WeakRef / WeakMap for caches that shouldn't prevent GC
  • Explicit .dispose() calls in panel unmount

Benchmarking

  • Project benchmark suite: benchmark/ directory
  • Run: cd benchmark && yarn start
  • Measures: message throughput, deserialization speed, render time
  • Use for before/after comparison when optimizing

Version History

  • cab9317 Current 2026-07-24 12:17

Same Skill Collection

.github/skills/3d-rendering/SKILL.md
.github/skills/caching-internals/SKILL.md
.github/skills/deserialization/SKILL.md
.github/skills/e2e-playwright-mcp/SKILL.md
.github/skills/electron-internals/SKILL.md
.github/skills/extensions-internals/SKILL.md
.github/skills/layouts-internals/SKILL.md
.github/skills/mcap-format/SKILL.md
.github/skills/message-path/SKILL.md
.github/skills/message-pipeline/SKILL.md
.github/skills/panel-extension-api/SKILL.md
.github/skills/panel-image/SKILL.md
.github/skills/panel-log/SKILL.md
.github/skills/panel-map/SKILL.md
.github/skills/panel-raw-messages/SKILL.md
.github/skills/panel-state-transitions/SKILL.md
.github/skills/panel-user-scripts/SKILL.md
.github/skills/player-internals/SKILL.md
.github/skills/plot-internals/SKILL.md
.github/skills/remote-caching/SKILL.md
.github/skills/test-conventions/SKILL.md
.github/skills/theme/SKILL.md
.github/skills/unit-testing/SKILL.md
.github/skills/web-workers/SKILL.md
.github/skills/websocket-connection/SKILL.md

Metadata

Files
0
Version
cab9317
Hash
1eccd406
Indexed
2026-07-24 12:17

Accueil - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-07 16:32
浙ICP备14020137号-1 $Carte des visiteurs$