Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Secondary indexes were holding open file descriptors throughout startup, and pool LRU evictions (triggered when N > 1024 indexes) unconditionally called
fdatasynceven for indexes with no pending writes — making startup cost superlinear in index count.Changes
WritableIndex.onBeforeClosefdatasyncwhenwriteBufferCursor === 0; previous guard (!this.writeBuffer) was always false sincewriteBufferis allocated ininitializeReadableStorage.openIndex+afterRegisterSecondaryIndexhookindex.open()call with a newafterRegisterSecondaryIndex(index)hookfileHandlePool.evict(index, false)—falsepreservesopened=trueand thedataarray soindex.length/index.lastEntryremain valid; the pool transparently reopens the fd on first real accessWritableStorage.afterRegisterSecondaryIndexopenIndexoverride: performs stale-entry truncation (needed after crash-recoverycheckTornWrites) while the fd is still live, then delegates tosuperto release itbench/bench-scalability.jsmeasureStartup/measureWrite/measureReadto awaitstorage.open(callback)so the async partition scan completes before reads — was causingPartition does not existerrors at runtimeBenchmark (Node v24, ~108 bytes/doc)
Scenario A — 1 index/partition:
Scenario B — 100 partitions, growing index count:
At low index counts the lazy fd release wins (Scenario B/100: −31% vs main); PR #339's snapshot approach dominates at high counts by skipping file opens entirely. The two are complementary. Write/read per-op latency is unchanged.