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-04 20:46:30 +00:00
2026-01-04 20:41:41 +00:00
2026-01-04 20:41:12 +00:00

Performance Module Test Suite

Comprehensive test coverage for the @claude-flow/performance module, focusing on Flash Attention optimization and benchmark validation.

Test Files

1. attention.test.ts (42 tests, 494 lines)

Tests for FlashAttentionOptimizer class and related functions.

Coverage Areas:

Initialization (3 tests)

  • Default and custom dimension initialization
  • Initial metrics validation

optimize() Method (6 tests)

  • Float32Array and number array input handling
  • Execution time tracking
  • Operation counting
  • Multiple keys/values support
  • Runtime detection (NAPI/WASM/JS)

benchmark() Method (6 tests)

  • Benchmark execution
  • Flash Attention performance measurement
  • Baseline performance measurement
  • Speedup calculation
  • V3 target validation (2.49x minimum)
  • Metrics tracking (peak speedup, success operations)

getSpeedup() Method (3 tests)

  • Zero operations case
  • Single benchmark speedup
  • Average across multiple benchmarks

getMetrics() Method (5 tests)

  • Initial metrics state
  • Operation counting
  • Average execution time calculation
  • Success rate tracking
  • Peak speedup tracking

resetMetrics() Method (2 tests)

  • Metrics reset to zero
  • Post-reset functionality

Memory Tracking (2 tests)

  • Node.js memory tracking
  • Graceful handling of missing memory API

Factory Functions (3 tests)

  • createFlashAttentionOptimizer() with default/custom dimensions
  • quickBenchmark() execution and validation

Performance Validation (3 tests)

  • Speedup improvement demonstration
  • Operations per second tracking
  • V3 target validation (2.49x-7.47x)

Edge Cases (4 tests)

  • Small dimensions (32D)
  • Large dimensions (2048D)
  • Single key/value pair
  • Many keys/values (100+)

2. benchmarks.test.ts (52 tests, 516 lines)

Tests for AttentionBenchmarkRunner class and formatting utilities.

Coverage Areas:

runComparison() Method (9 tests)

  • Default parameter execution
  • Flash Attention performance measurement
  • Baseline performance measurement
  • Speedup calculation
  • Target validation (2.49x)
  • Timestamp inclusion
  • Different dimensions (128, 256, 512, 1024)
  • Varying key counts (10, 50, 100, 200)
  • Execution time limits

runComprehensiveSuite() Method (6 tests)

  • Suite execution
  • Multiple dimension testing (5+ dimensions)
  • Summary statistics (avg, min, max speedup)
  • Success rate calculation
  • Target tracking
  • Timestamp inclusion

runMemoryProfile() Method (7 tests)

  • Default dimensions profiling
  • Multiple dimension profiling
  • Flash Attention memory measurement
  • Baseline memory measurement
  • Memory reduction calculation
  • Key count tracking
  • Custom dimension arrays

runStressTest() Method (5 tests)

  • Stress test execution
  • Increasing load testing
  • Dimension consistency
  • High key count handling (up to 5000)
  • Error handling

validateV3Targets() Method (5 tests)

  • V3 target validation
  • Minimum target check (2.49x)
  • Maximum target check (7.47x)
  • Valid speedup values
  • Correct dimension usage (512)

Formatting Functions (7 tests)

  • formatBenchmarkTable() output
  • Target status display
  • Success indicators (checkmarks)
  • formatSuiteReport() generation
  • Benchmark inclusion in reports
  • Summary statistics display
  • formatMemoryProfile() table generation

quickValidation() (2 tests)

  • Validation execution
  • Target meeting verification

Performance Validation (4 tests)

  • Consistent speedup across runs
  • Flash Attention performance improvement
  • Cross-dimension validation
  • Operations per second accuracy

Edge Cases (6 tests)

  • Very small dimensions (32D)
  • Very large dimensions (2048D)
  • Minimal iterations (10)
  • Many iterations (5000)
  • Empty dimension arrays
  • Single dimension arrays

Test Statistics

Total Test Files:     2
Total Tests:          94
Total Lines of Code:  1,010

Breakdown:
- attention.test.ts:   42 tests (494 lines)
- benchmarks.test.ts:  52 tests (516 lines)

All tests: PASSING ✓
Type Errors: 0

Running Tests

Run All Tests

npx vitest run __tests__/

Run Specific Test File

npx vitest run __tests__/attention.test.ts
npx vitest run __tests__/benchmarks.test.ts

Run with Coverage

npx vitest run __tests__/ --coverage

Watch Mode (Development)

npx vitest watch __tests__/

Verbose Output

npx vitest run __tests__/ --reporter=verbose

V3 Performance Targets Validated

The test suite validates against V3 performance targets:

  • Flash Attention Speedup: 2.49x - 7.47x (minimum 2.49x)
  • Memory Efficiency: Reduction tracking and validation
  • Operations/Second: Throughput measurement and comparison
  • Execution Time: <1s for optimization, reasonable benchmark times

Test Categories

  1. Unit Tests: Individual function and method testing
  2. Integration Tests: Component interaction testing
  3. Performance Tests: Speedup and efficiency validation
  4. Edge Case Tests: Boundary conditions and error handling
  5. Formatting Tests: Output formatting validation

Key Features Tested

  • Flash Attention optimization with multiple runtimes (NAPI/WASM/JS)
  • Benchmark comparison vs baseline (DotProductAttention)
  • Memory tracking and profiling
  • Comprehensive suite execution across dimensions
  • Stress testing with high key counts
  • V3 performance target validation
  • Metrics tracking (speedup, execution time, success rate)
  • Multiple dimension support (32D - 2048D)
  • Flexible input formats (Float32Array, number arrays)

Quality Metrics

  • Test Coverage: Comprehensive coverage of all public APIs
  • Test Quality: Mix of unit, integration, and performance tests
  • Edge Cases: Small/large dimensions, minimal/many iterations
  • V3 Alignment: All tests validate against V3 performance targets
  • TDD Approach: Tests follow London School methodology

Next Steps

To improve coverage further, consider:

  1. Add tests for benchmark.ts framework functions
  2. Add integration tests with real-world workloads
  3. Add regression tests with baseline data
  4. Add cross-platform runtime tests (NAPI vs WASM vs JS)
  5. Add memory leak detection tests
  6. Add concurrent execution tests

Dependencies

  • Vitest: Test framework (^1.0.0)
  • @ruvector/attention: Flash Attention implementation
  • TypeScript: Type checking during tests

Last Updated: 2026-01-04 Test Suite Version: 1.0.0