Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Differentiate methods/functions or fields in autocompletion for R6 class. #999

Closed
Fred-Wu opened this issue Feb 15, 2022 · 7 comments
Closed

Comments

@Fred-Wu
Copy link

Fred-Wu commented Feb 15, 2022

mlr3 is implemented with R6 class. However, after creating a task, all autocompletes appear to be fields. Some of them actually should be methods, such as data in the screenshot below.

image

Can these be differentiated within VSCode?

@Fred-Wu
Copy link
Author

Fred-Wu commented Jul 15, 2022

Just would like to check whether it is something easy to change?

@renkun-ken
Copy link
Member

Currently, we write out the names() of each object in the global environment on each top-level user input. To achieve this, we'll need to not only access names() but check if each child is a function, which could be a significant overhead given the way we gather such information at the moment.

The main difference here is only accessing names() or calling typeof() with each name. Here is some benchmarking:

get_names <- function(obj) {
  names(obj)
}

get_names_and_types <- function(obj) {
  names <- names(obj)
  vapply(names, function(name) {
    typeof(obj[[name]])
  }, character(1L))
}

For an object with many elements (e.g. baseenv()), the performance difference is like

env <- baseenv()
get_names(env)
get_names_and_types(env)

microbenchmark::microbenchmark(
  get_names(env),
  get_names_and_types(env)
)
Unit: microseconds
                     expr      min        lq      mean  median        uq      max neval
           get_names(env)  598.524  655.3905  738.7634  709.28  758.0825 2769.102   100
 get_names_and_types(env) 1433.744 1519.0875 1819.3571 1733.98 1804.9030 6086.458   100

But for small objects like a typical R6 classes, the performance difference is quite significant:

tsk <- mlr3::tsk("iris")
microbenchmark::microbenchmark(
  get_names(tsk),
  get_names_and_types(tsk)
)
Unit: microseconds
                     expr      min        lq       mean    median       uq      max neval
           get_names(tsk)    1.646    2.1385    4.17186    2.7675    5.080   32.734   100
 get_names_and_types(tsk) 1662.417 1993.9890 2212.53392 2040.4430 2310.729 4910.143   100

If our environment contains many objects like this, there will be obviously a notable delay on each user input given the current session watcher mechanism.

@ElianHugh
Copy link
Collaborator

Have we ever looked at saving a minimal globalenv representation + decompressing extension-side? E.g., using the protobuf format

@renkun-ken
Copy link
Member

renkun-ken commented Jul 16, 2022

The overhead of getting the information already seems significant. I think it might be use-able if we develop an on-demand mechanism that only access the info of a requested object, which requires two-way communication, as we discussed at #440 and #594.

@renkun-ken
Copy link
Member

If we have a vscode interactive window suggested in #700 which is built on top of a fully managed background R session, then it seems to be easier to manage these connections and conduct on-demand operations with the R session.

@github-actions
Copy link

This issue is stale because it has been open for 365 days with no activity.

@github-actions github-actions bot added the stale label Jul 17, 2023
@github-actions
Copy link

github-actions bot commented Aug 1, 2023

This issue was closed because it has been inactive for 14 days since being marked as stale.

@github-actions github-actions bot closed this as completed Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants