Skip to content

Fix code submission delays when the workspace viewer contains large number of objects#1713

Open
Fred-Wu wants to merge 2 commits into
REditorSupport:masterfrom
Fred-Wu:workspace-viewer-improve
Open

Fix code submission delays when the workspace viewer contains large number of objects#1713
Fred-Wu wants to merge 2 commits into
REditorSupport:masterfrom
Fred-Wu:workspace-viewer-improve

Conversation

@Fred-Wu

@Fred-Wu Fred-Wu commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR is to fix code submission delays when the workspace viewer contains large, wide, or deeply nested objects.

After every command, the workspace viewer inspected objects in the global environment to build their details. Inspecting and serialising this information could take significant time for large objects. Because the inspection runs in the active R session, R could not process newly submitted code until the workspace refresh finished, which causes noticeable delay between code submission and execution.

Workspace refreshes now collect only concise top-level metadata. Refreshes are delayed briefly, and repeated refresh requests are combined into a single refresh, allowing newly submitted code to run first. Detailed object metadata is lazy-loaded when an object is expanded.

Changes

  • Delay workspace refreshes briefly so newly submitted code can run first.
  • Combine repeated workspace refresh requests into a single refresh.
  • Lazy-load the next level of object metadata when expanded.
  • Support recursive expansion for lists, environments, pairlists, S4 objects, and data frames.
  • Paginate large objects into groups of 500 items, with ... loading the next page.
  • Remove inspection settings replaced by lazy loading:
    • r.session.objectLengthLimit
    • r.session.objectTimeout
    • r.session.levelOfObjectDetail
image image

Fred-Wu added 2 commits June 8, 2026 19:09
…arge objects by delaying workspace inspection until after command submission.

 - Fixed nested expansion in the workspace viewer for lists, environments, pairlists, S4 objects, and data frames.
 - Improved workspace viewer performance by loading object items on demand. Expanding an object shows the first 500 items directly, and selecting the ellipsis row loads the next 500.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses delays after code submission caused by eagerly inspecting/serializing large or deeply nested workspace objects in the active R session. It shifts the workspace viewer to a deferred + lazy-loading model and batches refresh requests so that newly submitted code can execute before workspace refresh work runs.

Changes:

  • Debounce and coalesce workspace refresh requests (and defer refresh when submitting code).
  • Return concise top-level workspace metadata and lazy-load nested object children on expansion, with pagination.
  • Add a new workspace_children request/handler path and adjust tests accordingly; remove now-obsolete inspection settings.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/workspaceViewer.ts Adds lazy-loading of object children, paging support, and updates tree refresh/eventing behavior.
src/session.ts Introduces debounced/coalesced workspace refresh scheduling and session-safety checks.
src/rTerminal.ts Defers workspace refresh when sending code to the terminal to reduce perceived submission latency.
sess/R/server.R Registers the new workspace_children request handler.
sess/R/handlers.R Implements lightweight workspace summaries and paginated child enumeration for expandable objects.
src/test/suite/session.test.ts Extends session communication tests to validate has_children and workspace_children.
package.json Removes workspace inspection settings replaced by lazy loading.
Comments suppressed due to low confidence (1)

src/rTerminal.ts:349

  • deferWorkspaceRefresh() is called before chooseTerminal(). If chooseTerminal() returns undefined (no terminals / user cancels), this cancels a pending workspace refresh and it will not be rescheduled until the next workspace_updated notification, leaving the workspace viewer stale. Move the call to after a terminal is successfully selected (right before sending text).
export async function runTextInTerm(text: string, execute: boolean = true): Promise<void> {
    deferWorkspaceRefresh();
    const term = await chooseTerminal();
    if (term === undefined) {
        return;
    }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/workspaceViewer.ts
Comment on lines +141 to +155
const page = await this.getGlobalEnvChildren(element);
const items: TreeItem[] = page.children.map(child =>
new GlobalEnvItem(
'',
child.class,
child.str.replace(/\s+/g, ' ').trim(),
child.type,
0,
element.treeLevel + 1,
undefined,
child.has_children,
element.rootName,
child.selector ? [...element.objectPath, child.selector] : element.objectPath
)
);
Comment thread src/workspaceViewer.ts
Comment on lines +248 to +256
}) as { children?: unknown, next_start?: unknown } | undefined;
if (response && Array.isArray(response.children)) {
const children = response.children.filter((child): child is WorkspaceChild =>
typeof child === 'object' &&
child !== null &&
'str' in child &&
'type' in child &&
'has_children' in child
);
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