-
Notifications
You must be signed in to change notification settings - Fork 93
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
Incremental resolving packages #204
Incremental resolving packages #204
Conversation
Do we actually want to keep the information of loaded libraries in |
Suppose we opened two documents using the following libraries: Document 1: library(foo) # which causes library(bar) Document 2: library(bar) Then document1's loaded libraries should be both If we store loaded libraries per document, it looks like we should change how |
I think that we could still cache the list of loaded libraries in |
Do you mean we could avoid paying the cost of unnecessary resolving (which is quite expensive) while keep loaded libraries stored per document at the same time? |
I think that's already been addressed in this PR. What I meant is, each document should keep a record of this loaded libraries Then there is also When a document is closed, the cached will be invalided and we should recompute the cache from In this way, we will be able to remove unnecessary attached libraries. |
Let's do an experiment for this. Suppose the following doc1: A B open doc1: This could work correctly. However, changing or saving documents may populate open doc1: |
I don't think I totally understand it. I imagine that |
I may misunderstand what you mean by |
|
Then the problem is that when we resolve Suppose there's doc1: A -> B Then |
Initially, Am I missing something? |
Yes, just got your point. You mean we could do it incrementally per document. This PR has done it on workspace level. |
@@ -51,7 +51,7 @@ constant_completion <- function(token) { | |||
#' Complete a package name | |||
#' @keywords internal | |||
package_completion <- function(token) { | |||
installed_packages <- rownames(utils::installed.packages()) | |||
installed_packages <- .packages(all.available = TRUE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dont even know this thing exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't know either. .packages(all.available = TRUE)
should be the fastest way to get all installed packages, find.package()
should be the fastest way to check if a package exists. utils::installed.packages()
reads all package metadata and thus has much more overhead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right
(randyimac)-~$ Rscript -e "system.time(for(i in 1:100) .packages(all.available = TRUE))"
user system elapsed
0.088 0.142 0.232
(randyimac)-~$ Rscript -e "system.time(for(i in 1:100) rownames(utils::installed.packages()))"
user system elapsed
0.272 0.047 0.320
LGTM, except that you need to |
Latest roxygen2 7.0+ will create documentation for R6 classes and produce a lot of warnings with the current docs. I reverted to roxygen 6.1.1 to redoc. |
Closes #203
This PR implements incremental package resolution so that resolving are done if and only if there are new packages appearing in the document that are not loaded in workspace.
This reduces all unnecessary package resolving on
didOpen
anddidSave
, significantly reduces the time of parse task in most cases, and also allows live loading packages on document didChange without having todidSave
(e.g. editing a temporary untitled document not intended to save on disk)