Files
rUv 33a2c3ed07 dream(performance): #3183 wire real cold-start measurement, remove fabricated V2-vs-V3 benchmark (evaluated, ACCEPT-scoped) (#3184)
* docs(dream-cycle): backfill LEDGER rows for 2026-08-24..09-03

Ledger-append step silently failed again for 10 consecutive nights
(3rd occurrence of this failure class, first flagged 2026-08-19).
Verified via git ls-remote + GitHub MCP issue/PR search before
concluding this (all 10 nights ran to completion: real branch, issue,
and draft PR each) rather than inferring failure from a sparse table.
2026-08-20..08-23 is a separate, confirmed-genuine 4-night gap where
the pipeline did not run at all.

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_01YQUz3bkMpqgtLXgkYa1LFF

* dream(performance): wire real cold-start measurement, remove fabricated V2-vs-V3 benchmark (evaluated, ACCEPT-scoped)

cli-cold-start.bench.ts's own measureColdStart() (a real,
spawn-based process timer) was never called anywhere in the file.
Every reported number instead came from setTimeout() delays,
including a "V2 vs V3 Speedup: 5.00x" that was guaranteed by
construction (setTimeout(100) vs setTimeout(20), no code between
them) regardless of any real behavior.

- Export measureColdStart(), add runRealColdStartMeasurement() and
  CLI_BIN_PATH; wire the real spawn-based measurement into the suite.
- Remove the fabricated V2-vs-V3 comparison outright (no V2 binary
  remains to honestly compare against).
- Add a deterministic Vitest regression test (4 assertions); fails
  against baseline (functions not exported, fabricated pattern still
  present), passes against candidate — confirmed via git-stash
  isolation. Full @claude-flow/performance suite: 99/99 passing.
  tsc --noEmit: clean.
- Real measured number: node bin/cli.js --version, 5 runs, mean
  54.65ms (min 51.94 / max 57.92) — well under the 500ms target.
  Caveat disclosed in-code: --version is the one subcommand that
  succeeds without a built dist/ in this worktree; this is not a
  full-CLI cold-start measurement.
- Correct the two stale "Achieved" claims this fed in
  ADR-STATUS-SUMMARY.md's Performance Targets table (CLI Startup,
  and the already-known-false HNSW 150x-12,500x figure one row up).

Darwin: skipped, scope mismatch (dead-code-wiring fix, not a
tunable parameter). Flywheel: no signed bundle, deterministic
Vitest evidence retained instead. Follow-ups documented in tonight's
gist: same anti-pattern in agent-spawn/mcp-server-init/cli-warm-start
bench files (not touched, kept to one conceptual change); a Raft
election safety gap and a plugin supply-chain enforcement gap found
by tonight's scan roles (hive-mind, security) but out of scope for
the performance DEEP surface.

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_01YQUz3bkMpqgtLXgkYa1LFF

* docs(dream-cycle): append 2026-09-05 ledger row

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_01YQUz3bkMpqgtLXgkYa1LFF

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-09-05 11:38:56 -04:00
..
2026-01-05 05:10:07 +00:00
2026-01-04 17:48:23 +00:00
2026-01-04 20:41:12 +00:00

@claude-flow/performance

npm version npm downloads License: MIT TypeScript Benchmarks

Comprehensive performance benchmarking module for Claude Flow V3 - statistical analysis, memory tracking, regression detection, and Flash Attention validation.

Features

  • Statistical Benchmarking - Mean, median, P95, P99, standard deviation, outlier removal
  • Memory Tracking - Heap, RSS, external, and array buffer monitoring
  • Auto-Calibration - Automatically adjusts iterations for statistical significance
  • Regression Detection - Compare against baselines with significance testing
  • V3 Performance Targets - Built-in targets for CLI, memory, swarm, and attention
  • Flash Attention Validation - Validate 2.49x-7.47x speedup targets
  • Multiple Output Formats - Console, JSON, and programmatic access

Installation

npm install @claude-flow/performance

Quick Start

import { benchmark, BenchmarkRunner, V3_PERFORMANCE_TARGETS } from '@claude-flow/performance';

// Single benchmark
const result = await benchmark('vector-search', async () => {
  await index.search(queryVector, 10);
}, {
  iterations: 100,
  warmup: 10
});

console.log(`Mean: ${result.mean}ms, P99: ${result.p99}ms`);

// Check against target
if (result.mean <= V3_PERFORMANCE_TARGETS['vector-search']) {
  console.log('Target met!');
}

API Reference

Single Benchmark

import { benchmark } from '@claude-flow/performance';

const result = await benchmark(
  'my-benchmark',
  async () => {
    // Code to benchmark
    await someOperation();
  },
  {
    iterations: 100,      // Number of iterations
    warmup: 10,           // Warmup iterations
    timeout: 30000,       // Timeout per iteration (ms)
    forceGC: false,       // Force GC between iterations
    minRuns: 10,          // Minimum runs for significance
    targetTime: 1000,     // Target time for auto-calibration (ms)
    metadata: {}          // Custom metadata
  }
);

// Result structure
{
  name: 'my-benchmark',
  iterations: 100,
  mean: 5.23,
  median: 4.98,
  p95: 8.12,
  p99: 12.45,
  min: 3.21,
  max: 15.67,
  stdDev: 1.45,
  opsPerSecond: 191.20,
  memoryUsage: { heapUsed, heapTotal, external, arrayBuffers, rss },
  memoryDelta: 1024000,
  timestamp: 1704067200000
}

Benchmark Suite

import { BenchmarkRunner } from '@claude-flow/performance';

const runner = new BenchmarkRunner('Memory Operations');

// Run individual benchmarks
await runner.run('vector-search', async () => {
  await index.search(query, 10);
});

await runner.run('memory-write', async () => {
  await store.write(entry);
});

// Or run all at once
const suite = await runner.runAll([
  { name: 'search', fn: () => search() },
  { name: 'write', fn: () => write() },
  { name: 'index', fn: () => index() }
]);

// Print results
runner.printResults();

// Export as JSON
const json = runner.toJSON();

Comparison & Regression Detection

import { compareResults, printComparisonReport } from '@claude-flow/performance';

// Compare current vs baseline
const comparisons = compareResults(baselineResults, currentResults, {
  'vector-search': 1,      // Target: <1ms
  'memory-write': 5,       // Target: <5ms
  'cli-startup': 500       // Target: <500ms
});

// Print formatted report
printComparisonReport(comparisons);

// Programmatic access
for (const comp of comparisons) {
  if (!comp.targetMet) {
    console.error(`${comp.benchmark} missed target!`);
  }
  if (comp.significant && !comp.improved) {
    console.warn(`${comp.benchmark} regressed by ${comp.changePercent}%`);
  }
}

V3 Performance Targets

import { V3_PERFORMANCE_TARGETS, meetsTarget } from '@claude-flow/performance';

// Built-in targets
V3_PERFORMANCE_TARGETS = {
  // Startup Performance
  'cli-cold-start': 500,        // <500ms (5x faster)
  'cli-warm-start': 100,        // <100ms
  'mcp-server-init': 400,       // <400ms (4.5x faster)
  'agent-spawn': 200,           // <200ms (4x faster)

  // Memory Operations
  'vector-search': 1,           // <1ms (150x faster)
  'hnsw-indexing': 10,          // <10ms
  'memory-write': 5,            // <5ms (10x faster)
  'cache-hit': 0.1,             // <0.1ms

  // Swarm Coordination
  'agent-coordination': 50,     // <50ms
  'task-decomposition': 20,     // <20ms
  'consensus-latency': 100,     // <100ms (5x faster)
  'message-throughput': 0.1,    // <0.1ms per message

  // SONA Learning
  'sona-adaptation': 0.05       // <0.05ms
};

// Check if target is met
const { met, target, ratio } = meetsTarget('vector-search', 0.8);
// { met: true, target: 1, ratio: 0.8 }

Formatting Utilities

import { formatBytes, formatTime } from '@claude-flow/performance';

formatTime(0.00005);  // '50.00 ns'
formatTime(0.5);      // '500.00 us'
formatTime(5);        // '5.00 ms'
formatTime(5000);     // '5.00 s'

formatBytes(1024);          // '1.00 KB'
formatBytes(1048576);       // '1.00 MB'
formatBytes(1073741824);    // '1.00 GB'

Running Benchmarks

# Run all benchmarks
npm run bench

# Run attention benchmarks
npm run bench:attention

# Run startup benchmarks
npm run bench:startup

Example Benchmark File

// benchmarks/memory.bench.ts
import { describe, bench } from 'vitest';
import { HNSWIndex } from '@claude-flow/memory';

describe('Memory Benchmarks', () => {
  const index = new HNSWIndex({ dimensions: 1536 });

  bench('vector-search', async () => {
    await index.search(queryVector, 10);
  }, { iterations: 1000 });

  bench('hnsw-indexing', async () => {
    await index.addPoint(id, vector);
  }, { iterations: 100 });
});

TypeScript Types

import type {
  BenchmarkResult,
  BenchmarkOptions,
  BenchmarkSuite,
  MemoryUsage,
  EnvironmentInfo,
  ComparisonResult,
  PerformanceTarget
} from '@claude-flow/performance';

Dependencies

  • @ruvector/attention - Flash Attention implementation
  • @ruvector/sona - SONA learning engine
  • vitest - Test/benchmark runner

License

MIT