Skip to content

perf: streamline R session refresh, replay, and console output - #1908

Merged
renkun-ken merged 4 commits into
mainfrom
codex/architecture-efficiency-1-4
Oct 25, 2026
Merged

renkun-ken merged 4 commits into
mainfrom
codex/architecture-efficiency-1-4

Conversation

@renkun-ken

Copy link
Copy Markdown
Member

Long-lived R sessions repeatedly rebuild unchanged workspace replies, scan retained output for small history requests, and resend growing console prefixes. This reduces that work while preserving session ownership, execution identity, replay, and final output timing.

  • Coalesce workspace inspection per session and send revision replies for unchanged structural metadata. Expanded child values still invalidate after execution/manual refresh. Structural inspection avoids custom methods, active method bindings, and large-vector copies.
  • Index journal execution ranges and display references, read archived history asynchronously, and bound the source/event working sets. Durable admission remains authoritative after cache eviction, interrupted appends, and coarse filesystem timestamps.
  • Negotiate bounded pull paging for oversized snapshots and live events. Active submissions remain present after reconnect even when JSON escaping exceeds the historical record allowance; paging stays tied to its original connection and preserves event order.
  • Give native sess connections monotonic request IDs, cancellation, timer cleanup, disconnect rejection, and bounded framing. Cached function metadata remains available while R is busy.
  • Append console suffixes to stable notebook outputs and index cells by execution ID. Acknowledgement follows VS Code's normalized output buffers, while removed cells and late writes release obsolete delivery state. Rich plots retain their identities.

Validation

Validated on macOS with a clean pnpm install --frozen-lockfile in an isolated checkout, TypeScript 7.0.2, VS Code types 1.101.0, Mocha 12.0.3, and VS Code 1.142.0:

  • 383 Node tests, including real R/arf runtime and library-isolation tests.
  • 177 affected provider/session/viewer tests and 12 real Interactive editor regressions.
  • Full rebuilt sess tinytest suite, TypeScript compilation, TypeScript/R lint, formatting, build, and diff checks.
  • Regressions cover unchanged nested values, active length-method bindings, escaped active code, prototype-named execution IDs, removed console buffers, output-clear races, stale paging, rotation, and torn appends.

The clean build succeeds with two existing EJS 7 export warnings in unchanged main help/httpgd imports. Cross-platform CI will validate the published head.

Local synthetic benchmarks

The branch includes scripts to reproduce these measurements:

Case Previous work Updated work
Unchanged workspace reply, 10,000 objects About 535 ms / 1.25 MB About 43 ms / 65 bytes
One-execution lookup in 112 MiB retained output About 47 ms About 0.05 ms with the index available
A 4 MiB console stream over 128 flushes 258 MiB of replacement payloads 4 MiB of appended payloads

Changed metadata still needs a full workspace reply, cold legacy indexes need reconstruction, and these timings do not measure end-to-end renderer latency. Live notebooks retain displayed history; the new byte limits govern working sets and transport pages.

@renkun-ken
renkun-ken requested a review from eitsupi October 25, 2026 03:56

@eitsupi eitsupi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ChatGPT review finding:

In WorkspaceRefreshScheduler.ensure(), dirty is cleared before read() completes. If the read fails or returns undefined, subsequent ensure() calls will not retry unless another invalidate() occurs.

This affects ensureSessionWorkspace() in particular: a transient native sess request failure could leave workspace metadata stale even when the user accesses it again.

Could we preserve the pending refresh after a failed read and retry on the next explicit ensure() call, without introducing an automatic retry loop?

@renkun-ken
renkun-ken merged commit 6505dad into main Oct 25, 2026
6 checks passed
@renkun-ken
renkun-ken deleted the codex/architecture-efficiency-1-4 branch October 25, 2026 04:22
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.

2 participants