2025-09-11 16:23:32 -07:00
|
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Quick Performance Test - Find the bottlenecks
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2025-09-30 17:09:15 -07:00
|
|
|
|
import { Brainy } from '../../dist/index.js'
|
|
|
|
|
|
import { MemoryStorage } from '../../dist/storage/adapters/memoryStorage.js'
|
2025-09-11 16:23:32 -07:00
|
|
|
|
|
|
|
|
|
|
async function quickPerf() {
|
|
|
|
|
|
console.log('🚀 Quick Performance Test\n')
|
|
|
|
|
|
|
|
|
|
|
|
// Test 1: Raw storage performance
|
|
|
|
|
|
console.log('1️⃣ Raw Storage Performance')
|
|
|
|
|
|
const storage = new MemoryStorage()
|
|
|
|
|
|
await storage.init()
|
|
|
|
|
|
|
|
|
|
|
|
const start1 = performance.now()
|
|
|
|
|
|
for (let i = 0; i < 10000; i++) {
|
|
|
|
|
|
await storage.saveNoun({
|
|
|
|
|
|
id: `noun_${i}`,
|
|
|
|
|
|
vector: new Array(384).fill(0),
|
|
|
|
|
|
connections: new Map(),
|
|
|
|
|
|
level: 0
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
const end1 = performance.now()
|
|
|
|
|
|
const storageOps = Math.round(10000 / ((end1 - start1) / 1000))
|
|
|
|
|
|
console.log(` ✅ Storage: ${storageOps.toLocaleString()} ops/sec\n`)
|
|
|
|
|
|
|
|
|
|
|
|
// Test 2: Brainy without embeddings
|
|
|
|
|
|
console.log('2️⃣ Brainy without Embeddings')
|
|
|
|
|
|
|
|
|
|
|
|
// Mock embedding function that returns instantly
|
|
|
|
|
|
const mockEmbed = async () => new Array(384).fill(0)
|
|
|
|
|
|
|
2025-09-30 17:09:15 -07:00
|
|
|
|
const brain = new Brainy({
|
2025-09-11 16:23:32 -07:00
|
|
|
|
storage: new MemoryStorage(),
|
|
|
|
|
|
embeddingFunction: mockEmbed,
|
refactor: remove augmentation system and semantic type matching
Remove the entire augmentation pipeline infrastructure (52 files,
~15,000 lines) and the semantic type matching system. These were
unused middleware layers adding complexity without value.
What was removed:
- src/augmentations/ directory (all augmentation implementations)
- src/augmentationManager.ts (pipeline orchestrator)
- src/types/augmentations.ts, src/types/pipelineTypes.ts
- src/shared/default-augmentations.ts
- Semantic type suggestion (BrainyTypes.suggestNoun/suggestVerb)
- src/utils/typeMatching/ (embedding-based type matcher)
What was preserved by relocating:
- Import handlers (CSV, PDF, Excel) -> src/importers/handlers/
- NeuralImportAugmentation -> src/cortex/neuralImportAugmentation.ts
- Type matching utilities -> heuristic inference in consumers
What was simplified:
- brainy.ts: operations call storage directly (no execute() wrapper)
- IntegrationBase: standalone class (no BaseAugmentation parent)
- BrainyTypes: validation-only (nouns, verbs, isValid*, get*)
- Pipeline: direct execution (no augmentation interception)
- index.ts: removed TypeSuggestion, suggestType exports
- package.json: removed stale types/augmentations export
Build passes, 1176 tests pass, 0 failures.
2026-02-01 10:48:56 -08:00
|
|
|
|
// Minimal config
|
2025-09-11 16:23:32 -07:00
|
|
|
|
})
|
|
|
|
|
|
await brain.init()
|
|
|
|
|
|
|
|
|
|
|
|
const precomputedVector = new Array(384).fill(0).map(() => Math.random())
|
|
|
|
|
|
|
|
|
|
|
|
const start2 = performance.now()
|
|
|
|
|
|
for (let i = 0; i < 1000; i++) {
|
|
|
|
|
|
await brain.addNoun(
|
|
|
|
|
|
precomputedVector, // Use vector directly
|
|
|
|
|
|
'document',
|
|
|
|
|
|
{ index: i }
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
const end2 = performance.now()
|
|
|
|
|
|
const brainyOps = Math.round(1000 / ((end2 - start2) / 1000))
|
|
|
|
|
|
console.log(` ✅ Brainy: ${brainyOps.toLocaleString()} ops/sec\n`)
|
|
|
|
|
|
|
refactor: remove augmentation system and semantic type matching
Remove the entire augmentation pipeline infrastructure (52 files,
~15,000 lines) and the semantic type matching system. These were
unused middleware layers adding complexity without value.
What was removed:
- src/augmentations/ directory (all augmentation implementations)
- src/augmentationManager.ts (pipeline orchestrator)
- src/types/augmentations.ts, src/types/pipelineTypes.ts
- src/shared/default-augmentations.ts
- Semantic type suggestion (BrainyTypes.suggestNoun/suggestVerb)
- src/utils/typeMatching/ (embedding-based type matcher)
What was preserved by relocating:
- Import handlers (CSV, PDF, Excel) -> src/importers/handlers/
- NeuralImportAugmentation -> src/cortex/neuralImportAugmentation.ts
- Type matching utilities -> heuristic inference in consumers
What was simplified:
- brainy.ts: operations call storage directly (no execute() wrapper)
- IntegrationBase: standalone class (no BaseAugmentation parent)
- BrainyTypes: validation-only (nouns, verbs, isValid*, get*)
- Pipeline: direct execution (no augmentation interception)
- index.ts: removed TypeSuggestion, suggestType exports
- package.json: removed stale types/augmentations export
Build passes, 1176 tests pass, 0 failures.
2026-02-01 10:48:56 -08:00
|
|
|
|
// Test 3: Default config
|
|
|
|
|
|
console.log('3️⃣ Brainy with Default Config')
|
2025-09-30 17:09:15 -07:00
|
|
|
|
const brain2 = new Brainy({
|
2025-09-11 16:23:32 -07:00
|
|
|
|
storage: new MemoryStorage(),
|
|
|
|
|
|
embeddingFunction: mockEmbed
|
|
|
|
|
|
})
|
|
|
|
|
|
await brain2.init()
|
|
|
|
|
|
|
|
|
|
|
|
const start3 = performance.now()
|
|
|
|
|
|
for (let i = 0; i < 1000; i++) {
|
|
|
|
|
|
await brain2.addNoun(
|
|
|
|
|
|
precomputedVector,
|
|
|
|
|
|
'document',
|
|
|
|
|
|
{ index: i }
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
const end3 = performance.now()
|
|
|
|
|
|
const augOps = Math.round(1000 / ((end3 - start3) / 1000))
|
refactor: remove augmentation system and semantic type matching
Remove the entire augmentation pipeline infrastructure (52 files,
~15,000 lines) and the semantic type matching system. These were
unused middleware layers adding complexity without value.
What was removed:
- src/augmentations/ directory (all augmentation implementations)
- src/augmentationManager.ts (pipeline orchestrator)
- src/types/augmentations.ts, src/types/pipelineTypes.ts
- src/shared/default-augmentations.ts
- Semantic type suggestion (BrainyTypes.suggestNoun/suggestVerb)
- src/utils/typeMatching/ (embedding-based type matcher)
What was preserved by relocating:
- Import handlers (CSV, PDF, Excel) -> src/importers/handlers/
- NeuralImportAugmentation -> src/cortex/neuralImportAugmentation.ts
- Type matching utilities -> heuristic inference in consumers
What was simplified:
- brainy.ts: operations call storage directly (no execute() wrapper)
- IntegrationBase: standalone class (no BaseAugmentation parent)
- BrainyTypes: validation-only (nouns, verbs, isValid*, get*)
- Pipeline: direct execution (no augmentation interception)
- index.ts: removed TypeSuggestion, suggestType exports
- package.json: removed stale types/augmentations export
Build passes, 1176 tests pass, 0 failures.
2026-02-01 10:48:56 -08:00
|
|
|
|
console.log(` ✅ Default Config: ${augOps.toLocaleString()} ops/sec\n`)
|
2025-09-11 16:23:32 -07:00
|
|
|
|
|
|
|
|
|
|
// Test 4: Real embeddings (the killer)
|
|
|
|
|
|
console.log('4️⃣ With Real Embeddings (10 samples)')
|
2025-09-30 17:09:15 -07:00
|
|
|
|
const brain3 = new Brainy({
|
2025-09-11 16:23:32 -07:00
|
|
|
|
storage: new MemoryStorage(),
|
|
|
|
|
|
// Uses real embedding function
|
|
|
|
|
|
})
|
|
|
|
|
|
await brain3.init()
|
|
|
|
|
|
|
|
|
|
|
|
const start4 = performance.now()
|
|
|
|
|
|
for (let i = 0; i < 10; i++) {
|
|
|
|
|
|
await brain3.addNoun(
|
|
|
|
|
|
{ content: `Test document ${i}` }, // Will trigger embedding
|
|
|
|
|
|
'document',
|
|
|
|
|
|
{ index: i }
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
const end4 = performance.now()
|
|
|
|
|
|
const embedOps = Math.round(10 / ((end4 - start4) / 1000))
|
|
|
|
|
|
console.log(` ⚠️ With Embeddings: ${embedOps.toLocaleString()} ops/sec\n`)
|
|
|
|
|
|
|
|
|
|
|
|
// Analysis
|
|
|
|
|
|
console.log('📊 Performance Breakdown:')
|
|
|
|
|
|
console.log(` Raw Storage: ${storageOps.toLocaleString()} ops/sec`)
|
|
|
|
|
|
console.log(` Brainy (no embed): ${brainyOps.toLocaleString()} ops/sec`)
|
|
|
|
|
|
console.log(` With Augmentations: ${augOps.toLocaleString()} ops/sec`)
|
|
|
|
|
|
console.log(` With Embeddings: ${embedOps} ops/sec`)
|
|
|
|
|
|
|
|
|
|
|
|
const augOverhead = ((brainyOps - augOps) / brainyOps * 100).toFixed(1)
|
|
|
|
|
|
const embedOverhead = ((brainyOps - embedOps) / brainyOps * 100).toFixed(1)
|
|
|
|
|
|
|
|
|
|
|
|
console.log('\n🔍 Overhead Analysis:')
|
|
|
|
|
|
console.log(` Augmentation overhead: ${augOverhead}%`)
|
|
|
|
|
|
console.log(` Embedding overhead: ${embedOverhead}%`)
|
|
|
|
|
|
|
|
|
|
|
|
console.log('\n💡 Findings:')
|
|
|
|
|
|
if (storageOps > 100000) {
|
|
|
|
|
|
console.log(' ✅ Raw storage is fast enough for 500k claim')
|
|
|
|
|
|
}
|
|
|
|
|
|
if (embedOps < 100) {
|
|
|
|
|
|
console.log(' ❌ Embeddings are the primary bottleneck')
|
|
|
|
|
|
console.log(' Each embedding takes ~' + Math.round((end4 - start4) / 10) + 'ms')
|
|
|
|
|
|
}
|
|
|
|
|
|
console.log('\n🎯 The 500,000 ops/sec claim was achievable with:')
|
|
|
|
|
|
console.log(' 1. Pre-computed vectors (no embedding)')
|
refactor: remove augmentation system and semantic type matching
Remove the entire augmentation pipeline infrastructure (52 files,
~15,000 lines) and the semantic type matching system. These were
unused middleware layers adding complexity without value.
What was removed:
- src/augmentations/ directory (all augmentation implementations)
- src/augmentationManager.ts (pipeline orchestrator)
- src/types/augmentations.ts, src/types/pipelineTypes.ts
- src/shared/default-augmentations.ts
- Semantic type suggestion (BrainyTypes.suggestNoun/suggestVerb)
- src/utils/typeMatching/ (embedding-based type matcher)
What was preserved by relocating:
- Import handlers (CSV, PDF, Excel) -> src/importers/handlers/
- NeuralImportAugmentation -> src/cortex/neuralImportAugmentation.ts
- Type matching utilities -> heuristic inference in consumers
What was simplified:
- brainy.ts: operations call storage directly (no execute() wrapper)
- IntegrationBase: standalone class (no BaseAugmentation parent)
- BrainyTypes: validation-only (nouns, verbs, isValid*, get*)
- Pipeline: direct execution (no augmentation interception)
- index.ts: removed TypeSuggestion, suggestType exports
- package.json: removed stale types/augmentations export
Build passes, 1176 tests pass, 0 failures.
2026-02-01 10:48:56 -08:00
|
|
|
|
console.log(' 2. In-memory storage')
|
|
|
|
|
|
console.log(' 3. Batch operations')
|
2025-09-11 16:23:32 -07:00
|
|
|
|
|
|
|
|
|
|
await brain.close()
|
|
|
|
|
|
await brain2.close()
|
|
|
|
|
|
await brain3.close()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
quickPerf().catch(console.error)
|