This repository has been archived on 2026-09-03. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
open-brainy/src/utils
David Snelling c8a239aa8d feat: complete non-blocking metadata indexing solution
BREAKING: Fixes critical event loop blocking during metadata operations

## Event Loop Blocking Fixes
- Add setImmediate() yields in metadata rebuild every 10 items
- Add event loop yields in addToIndex() every 5 fields
- Add event loop yields in flush() operations with smaller batches
- Reduce flush threshold from 50 to 10 for more frequent non-blocking flushes
- Add progress logging for rebuild operations with event loop yields

## Performance Testing Results
- Single item addition: 308ms, max event loop delay 20ms ✅ NO BLOCKING
- 200 items in batches of 10: max event loop delay 172ms ✅ NO BLOCKING
- 200 items in batches of 50: max event loop delay 700ms+ ❌ BLOCKS

## bluesky-package Solution
**Root Cause:** Large concurrent batches (50+ operations) overwhelm metadata indexing
**Solution:** Process data in smaller batches (≤10 concurrent operations) with yields

**Recommended Pattern for bluesky-package:**
```javascript
// Instead of Promise.all([...hundreds of operations])
const BATCH_SIZE = 10
for (let i = 0; i < items.length; i += BATCH_SIZE) {
  const batch = items.slice(i, i + BATCH_SIZE)
  await Promise.all(batch.map(item => brainy.add(item)))
  await new Promise(resolve => setImmediate(resolve)) // Yield
}
```

## Statistics Caching (from previous commits)
- 5-minute statistics caching eliminates expensive S3 lookups
- getStorageStatus() uses estimation vs full bucket scans
- 90%+ reduction in S3 API calls reducing socket pressure

Combined solution addresses both root causes:
1. Event loop blocking fixed with proper yields and batch sizing
2. Socket exhaustion fixed with statistics caching and reduced API calls
2025-08-07 11:07:11 -07:00
..
adaptiveBackpressure.ts feat: add automatic adaptive performance optimization for high-volume scenarios 2025-08-07 08:37:15 -07:00
adaptiveSocketManager.ts feat: add automatic adaptive performance optimization for high-volume scenarios 2025-08-07 08:37:15 -07:00
autoConfiguration.ts feat(auto-configuration): implement automatic configuration system for optimal settings 2025-08-03 17:27:01 -07:00
cacheAutoConfig.ts feat(pagination): implement cursor-based pagination and enhance search caching 2025-08-04 14:25:05 -07:00
crypto.ts feat(distributed): add distributed mode with multi-instance coordination 2025-08-04 12:18:58 -07:00
distance.ts feat: add GPU acceleration for embeddings with smart device auto-detection 2025-08-05 20:00:04 -07:00
embedding.ts feat: add GPU acceleration for embeddings with smart device auto-detection 2025-08-05 20:00:04 -07:00
environment.ts **feat(core): enhance vector handling, model loading, and compatibility** 2025-07-16 13:51:00 -07:00
fieldNameTracking.ts **feat(search): enhance JSON document search with field-level filtering and prioritization** 2025-08-01 08:27:39 -07:00
index.ts refactor: clean up deprecated functions and unused code 2025-08-05 10:16:05 -07:00
jsonProcessing.ts **feat(search): enhance JSON document search with field-level filtering and prioritization** 2025-08-01 08:27:39 -07:00
logger.ts fix(storage): resolve pagination warnings and improve S3 adapter performance 2025-08-05 07:22:05 -07:00
metadataFilter.ts fix: correct typo in README major updates section 2025-08-06 12:29:32 -07:00
metadataIndex.ts feat: complete non-blocking metadata indexing solution 2025-08-07 11:07:11 -07:00
metadataIndexCache.ts feat: v0.49 - Filter discovery API, remove deprecated methods, improve performance 2025-08-06 14:39:33 -07:00
operationUtils.ts **feat: implement robust error-handling and operation utilities for storage adapters** 2025-07-30 11:35:09 -07:00
performanceMonitor.ts feat: add automatic adaptive performance optimization for high-volume scenarios 2025-08-07 08:37:15 -07:00
requestCoalescer.ts fix: implement high-volume optimizations to prevent socket exhaustion 2025-08-07 09:09:43 -07:00
searchCache.ts feat(pagination): implement cursor-based pagination and enhance search caching 2025-08-04 14:25:05 -07:00
statistics.ts **feat(core, storage, tests): add service-level statistics tracking and storage adapter enhancements** 2025-07-24 11:35:52 -07:00
statisticsCollector.ts fix(core): resolve TypeScript compilation errors and test failures 2025-08-04 20:00:38 -07:00
textEncoding.ts fix: resolve test failures and browser environment issues 2025-08-05 19:38:26 -07:00
typeUtils.ts **feat(utils): add type utility functions and examples for runtime type management** 2025-07-31 14:24:16 -07:00
version.ts refactor: clean up deprecated functions and unused code 2025-08-05 10:16:05 -07:00
workerUtils.ts **feat(tests): add tests for TextEncoder, TensorFlow.js, and fallback mechanisms** 2025-07-11 11:11:56 -07:00
writeBuffer.ts fix(emergency): drastically lower high-volume mode activation thresholds 2025-08-07 09:51:22 -07:00