Skip to content

facebook/memlab

⭐ 4,964  ·  #7  ·  JavaScript

A framework for finding JavaScript memory leaks and analyzing heap snapshots

JavaScript detector e2e facebook Memory

项目分析

🎯 定位持久记忆系统
💡 核心价值解决 AI Agent 每次对话都从零开始的问题。通过文件存储、数据库或向量检索等方式,让 Agent 拥有跨会话的持久记忆,记住用户偏好、项目上下文和历史决策
👥 适合谁需要 Agent 保持长期上下文的开发者,比如项目管理、大型代码库熟悉等场景

为什么值得关注

4,964 Stars,处于快速增长阶段,值得早期关注。使用 JavaScript 开发。

AI 深度分析报告

Summary

Automated framework for locating JS memory leaks and analyzing heap snapshots.

Core Features

  • Automated Leak Detection: Automatically captures and compares heap snapshots through E2E test scenario replay, identifying objects not reclaimed by GC.
  • In-depth Heap Snapshot Analysis: Provides structured APIs (e.g., HeapAnalysis) to traverse V8/Hermes heap graphs, supporting custom queries to match leak patterns.
  • Dual Support for Browser and Node.js: Can interface with Puppeteer/Playwright to drive Chrome, or directly analyze Node.js process heaps.
  • Hermes Engine Compatibility: Optimized for React Native's Hermes engine, supporting its heap snapshot format.
  • Visualization and Export: Generates retention path graphs for leaked objects, supports JSON snapshot export for secondary analysis.

Technical Architecture

  • Language and Runtime: Pure TypeScript/JavaScript implementation, relies on Node.js for core analysis logic.
  • Heap Processing Engine: Builds an in-memory graph model based on the V8 heap snapshot protocol (.heapsnapshot) and Hermes snapshot format.
  • Code Structure Highlights:
    • Modular analysis pipeline: SnapshotHeapNodeEdgeAnalyzer, supporting pluggable custom analyzers.
    • Test-driven design: Built-in memlab test command, coupling leak detection with E2E test workflows.
    • Separation of CLI and API: Provides both the memlab command-line tool and the programmatic memlab npm package.

Quick Start Guide

bash
# Installation
npm install -g memlab

# Run leak detection on a specified URL (automatically opens browser)
memlab test --scenario "https://example.com"

# Analyze a local heap snapshot
memlab analyze /path/to/heap.heapsnapshot

# Programmatic usage (Node.js)
import { takeHeapSnapshot, diffHeapSnapshots } from 'memlab';
const snap1 = takeHeapSnapshot();
// ... perform operations ...
const snap2 = takeHeapSnapshot();
const leaks = diffHeapSnapshots(snap1, snap2);

Strengths, Weaknesses, and Use Cases

Strengths:

  • High degree of automation: No need to manually record heap snapshots; integrates with E2E tests for continuous monitoring.
  • Deep analysis capability: Supports custom object matching rules, capable of detecting complex leaks such as closures and DOM references.
  • Community backing: Maintained by Facebook/Meta, deeply integrated with the React Native ecosystem.

Weaknesses:

  • Learning curve: Requires understanding of V8 heap graph concepts (nodes, edges, retention paths), not intuitive.
  • Performance overhead: Analysis of large heap snapshots (>500MB) is time-consuming, unsuitable for real-time online monitoring.
  • Platform limitations: Only supports V8 and Hermes engines, cannot be used with JSC or other JS engines.

Use Cases:

  • Frontend teams: Memory leak investigation in React/React Native applications.
  • Performance engineers: Embedding memory regression detection into E2E test pipelines.
  • Node.js backend: Heap analysis for long-running services (e.g., microservices).

Community and Popularity

  • Stars: 4,964 (as of May 2026), showing steady growth, ranking among the top memory analysis tools.
  • Forks: Approximately 300+, with active contributors primarily from Meta developers; external PRs are fewer.
  • Recent Updates: Commits still present in May 2026 (e.g., Hermes snapshot compatibility fixes), but the core API has remained largely unchanged since 2024, indicating maturity and stability.
  • Issues: Approximately 100+ open, mainly feature requests and Hermes-specific issues, with moderate response time (1-2 weeks).

技术信息

  • 💻 语言: JavaScript
  • 📂 Topics: detector, e2e, facebook, heap, hermes
  • 🕐 更新: 2026-05-09
  • 🔗 访问 GitHub 仓库

数据更新于 2026-05-09 · Stars 数以 GitHub 实际数据为准

热点项目数据来自 GitHub API,实时更新