Repository navigation
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. |
| #' @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.
dont even know this thing exists.
There was a problem hiding this comment.
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.
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
didOpenanddidSave, 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)