Skip to content

Conversation

@renkun-ken
Copy link
Member

@renkun-ken renkun-ken commented Sep 8, 2021

What problem did you solve?

Closes #174

This PR introduces a new setting r.session.objectLengthLimit corresponding to R option vsc.object_length_limit to limit the length of objects to provide names in session symbol completion, hover, and workspace viewer item.

Then large named objects with many elements will not be called names(). The overhead of calling names() (on environment) and writing the names to globalenv.json should be reduced.

(If you do not have screenshot) How can I check this pull request?

For the following code, before this PR, the delay will be more and more significant if more objects with many elements are created in the global environment.

n1 <- seq_len(1000)
lst1 <- lapply(n1, function(i) i)
names(lst1) <- paste0("name", n1)

1 + 1 # no delay

n2 <- seq_len(5000)
lst2 <- lapply(n2, function(i) i)
names(lst2) <- paste0("name", n2)

1 + 1 # slight delay

n3 <- seq_len(100000)
lst3 <- lapply(n3, function(i) i)
names(lst3) <- paste0("name", n3)

1 + 1 # significant delay

With this PR being effective, creating lst2 and lst3 should no longer cause a permanent delay on all subsequent calculations. One should also observe that the auto-completion works with lst1 but not lst2 or lst3 due to object length limit, and the workspace viewer item of lst1 should show object details while lst2 and lst3 do not if r.session.levelOfObjectDetail is set to Detailed. Adjusting r.session.objectLengthLimit should work accordingly.

@renkun-ken renkun-ken requested a review from ElianHugh September 8, 2021 08:09
@ElianHugh
Copy link
Collaborator

Thanks for the quick fix! I've had a look over the commit and it looks good. I'll have a chance to try the PR in an hour or so

@ElianHugh
Copy link
Collaborator

Thank you for the good work, it all works quite nicely! The only (very minor) issue I've had is the console complaining about undefined properties:

Error Cannot read property 'map' of undefined: TypeError: Cannot read property 'map' of undefined
	at LiveCompletionItemProvider.provideCompletionItems (/home/elian/Documents/Coding/vscode-R/out/completions.js:111:22)
	at $.provideCompletionItems (/var/lib/snapd/snap/code/73/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:94:176938)

@renkun-ken
Copy link
Member Author

I made some changes to the completions to achieve the following:

  • The errors should be gone since checks are added.
  • The order of object elements are preserved.

Copy link
Collaborator

@ElianHugh ElianHugh left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks again!

@renkun-ken renkun-ken merged commit 892439b into REditorSupport:master Sep 9, 2021
ElianHugh pushed a commit to ElianHugh/vscode-R that referenced this pull request May 12, 2022
* Add object length limit

* Update inspect_env

* Preserve the order of names in completion
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.

Reduce overhead of session watcher task callback

2 participants