Skip to content

perf(listing): coalesce entry stream delivery - #5

Merged
yfcyrus merged 3 commits into
mainfrom
perf/coalesce-entry-stream
Nov 5, 2026
Merged

yfcyrus merged 3 commits into
mainfrom
perf/coalesce-entry-stream

Conversation

@yfcyrus

@yfcyrus yfcyrus commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

perf: coalesce entry stream delivery

Why

Large streaming listings flooded the JS thread: each native flush became one subscribeEntries callback (~600 × 10 for 6,000 files with SDs). Native work finished first; JS was still draining small batches after Task completed.

What

  • EntryStream uses notify-and-drain: append wakes each subscriber at most once until it drains; drainEntries returns everything since the last drain.
  • SmbListTask.subscribeEntries API unchanged (replay, order, pre-terminal delivery).
  • batchSize / 100 ms still control native flushes only.
Before After
JS callbacks (6k + SD) ~600 ~50–100
After Task completed long tail of size-10 batches at most one trailing batch, then wait()

Design

Append stores entries and signals only if not already scheduled. JS drains entries_[cursor..end] on each wake (and once on subscribe for replay). Busy JS coalesces several flushes into one batch; idle JS still sees ~batchSize.

Notes for reviewers

  • Native bridge adds payload-free subscribeEntries + drainEntries; public API unchanged.

Replace per-flush entry pushes with a payload-free signal per subscriber and a
drainEntries pull, so a busy JS thread queues at most one pending delivery and
receives every entry appended since its last drain in one batch.

- track a cursor and scheduled flag per EntryStream subscriber instead of pushing each batch
- add drainEntries to SmbTask and NativeSmbListTask
- drain once right after subscribing so late subscribers still get the replay
- keep SmbListTask.subscribeEntries API, server order, and delivery before terminal status
Model the native cursor and deferred signals in FakeNativeListTask so
coalescing, replay, and unsubscribe behavior stay covered without a device.

- merge several appends behind one pending signal into a single batch
- ignore signals that arrive after unsubscribe
- drain the last entries before the terminal status settles
Describe how entry batches merge while the JS thread is busy and how batchSize
and the 100ms delay now control native flushes rather than JS callbacks.

- update subscribeEntries notes in API, task model, and architecture docs
- clarify batch timing in the listDirectory JSDoc
@yfcyrus
yfcyrus merged commit d93586c into main Nov 5, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant