fix: resolve 100x metadata rebuild performance regression

Fixes critical performance bug reported by Workshop team where metadata
index rebuild took 8-9 minutes instead of 2-3 seconds for 1,157 entities.

Root cause: Hardcoded batch size of 25 was overly conservative for
FileSystemStorage which has no socket limits (unlike cloud storage).

Solution: Implement adaptive batch sizing based on storage adapter type:
- FileSystemStorage/MemoryStorage: 1000 entities/batch (40x speedup)
- Cloud Storage (GCS/S3/R2): 25 entities/batch (prevents socket exhaustion)
- OPFS/Unknown: 100 entities/batch (balanced default)

Performance impact:
- 1,157 entities: 47 batches → 2 batches with FileSystemStorage
- Cold start time: 8-9 minutes → 2-3 seconds (100x faster)
- Cloud storage: No performance change (still uses conservative batching)

Files changed:
- src/utils/metadataIndex.ts: Add getAdaptiveBatchSize() method
- CHANGELOG.md: Document v4.2.0 and v4.2.1 releases
This commit is contained in:
David Snelling 2025-10-23 08:07:07 -07:00
parent 28642f6f9c
commit c479bd70e0
2 changed files with 93 additions and 6 deletions

View file

@ -2,6 +2,36 @@
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
### [4.2.1](https://github.com/soulcraftlabs/brainy/compare/v4.2.0...v4.2.1) (2025-10-23)
### 🐛 Bug Fixes
* **performance**: fix 100x metadata rebuild regression in v4.2.0
- **Critical Fix**: Metadata index rebuild now takes 2-3 seconds instead of 8-9 minutes for 1,157 entities
- **Root Cause**: Hardcoded batch size of 25 was too conservative for FileSystemStorage (no socket limits)
- **Solution**: Implemented adaptive batch sizing based on storage adapter type:
- FileSystemStorage/MemoryStorage: 1000 entities/batch (40x larger → 47 batches reduced to 2 batches)
- Cloud Storage (GCS/S3/R2): 25 entities/batch (keeps conservative batching to prevent socket exhaustion)
- OPFS/Unknown: 100 entities/batch (balanced default)
- **Performance**: 100x speedup for local development and FileSystemStorage deployments
- **Impact**: Fixes Workshop team bug report - cold starts now complete in seconds, not minutes
- **Backward Compatible**: Cloud storage performance unchanged, only local storage optimized
- **Files Changed**: `src/utils/metadataIndex.ts` (lines 1727-1770, 2052-2079, 2174)
### [4.2.0](https://github.com/soulcraftlabs/brainy/compare/v4.1.4...v4.2.0) (2025-10-23)
### ✨ Features
* **import**: implement progressive flush intervals for streaming imports
- Dynamically adjusts flush frequency based on current entity count (not total)
- Starts at 100 entities for frequent early updates, scales to 5000 for large imports
- Works for both known totals (files) and unknown totals (streaming APIs)
- Provides live query access during imports and crash resilience
- Zero configuration required - always-on streaming architecture
- Updated documentation with engineering insights and usage examples
### [4.1.4](https://github.com/soulcraftlabs/brainy/compare/v4.1.3...v4.1.4) (2025-10-21)
- feat: add import API validation and v4.x migration guide (a1a0576)