Skip to content

RStudio is executing RMarkdown / Quarto chunks very slowely when working on a network drive, especially when inside a project. #14619

Closed

Description

@marianklose

System details

RStudio Edition : Desktop
RStudio Version : RStudio 2024.04.0+735 "Chocolate Cosmos" Release (a00d0e775dbc93e0d79a1bf474e3e8e8de677383, 2024-04-24) for windows Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) RStudio/2024.04.0+735 Chrome/120.0.6099.291 Electron/28.2.6 Safari/537.36, Quarto 1.3.450
OS Version      : x86_64-w64-mingw32 (windows 10)
R Version       : R version 4.3.0 (2023-04-21 ucrt) (Already Tomorrow)

Steps to reproduce the problem

  1. Create test.qmd (or test.Rmd) file with the following single chunk of code. Also create test.R with the same code, so just without the {r} chunk markup.
```{r}
# define start time
start_time <- Sys.time()

# dummy code
1+1
1+1
1+1
1+1
1+1
1+1
1+1
1+1
1+1
1+1
1+1
1+1
1+1
1+1
1+1
1+1
1+1
1+1
1+1
1+1
1+1
1+1
1+1
1+1
1+1
1+1

# define end time
end_time <- Sys.time()

# calculate elapsed time
difftime(end_time, start_time, units = "secs")
```
  1. Open test.qmd and execute chunk in RStudio within various scenarios. Compare difftime (time to execute chunk)
    a) local drive, no project
    test.qmd: Time difference of 0.08611608 secs
    test.R: Time difference of 0.01601291 secs
    b) local drive, within project
    test.qmd: Time difference of 0.08609295 secs
    test.R: Time difference of 0.01690793 secs
    c) mapped / shared network drive, no project
    test.qmd: Time difference of 0.26181581 secs
    test.R: Time difference of 0.01711988 secs
    d) mapped / shared network drive, within project
    test.qmd: Time difference of 1.60444383 secs
    test.R: Time difference of 0.01676202 secs

Describe the problem in detail

We can see that while the execution of test.R is nearly unaffected by both the project/no project setting and the shared / local drive setting, the test.qmd chunk execution is highly impacted. We can observe a nearly 20-fold longer execution time for the chunk inside test.qmd when comparing the d) mapped / shared network drive, within project scenario with the a) local drive, no project or b) local drive, within project scenarios. The same behaviour is reproducible for test.Rmd instead of test.qmd.

This issue is related to #8034 (which was closed with the request to open a new issue if there are still problems) and #10417.

Describe the behavior you expected

I would expect the same execution time for the chunk inside test.qmd no matter what scenario (a/b/c/d) we are in. To me, this behaviour makes it very hard to use projects and/or Quarto or RMarkdown files when on a mapped / shared network drive.

  • I have read the guide for submitting good bug reports.
  • I have installed the latest version of RStudio, and confirmed that the issue still persists.
  • If I am reporting an RStudio crash, I have included a diagnostics report.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

Activity

  1. added
    new
    on Apr 30, 2024
  2. removed
    new
    on Apr 30, 2024
  3. added
    remote storage
    on May 6, 2024
  4. ronblum commented on May 6, 2024

    @ronblum
    Contributor

    See also #10417.

  5. added this to the Later milestone on May 6, 2024
  6. nschan commented on May 17, 2024

    @nschan

    I am experiencing similar problems. I suspect they are related to the use of renv, are you using renv @marianklose ? For me there is a noticable increase in performance after renv::deactivate().

  7. marianklose commented on May 17, 2024

    @marianklose
    Author

    Hi @nschan, thanks for your suggestion. For me it is actually not related to renv. But I haven't tested if using renv is slowing down the process even more.

    > renv::status()
    This project does not appear to be using renv.
    Use `renv::init()` to initialize the project.
    
  8. kevinushey commented on May 29, 2024

    @kevinushey
    Collaborator

    @marianklose: would you be willing to help us collect some more information? There is a Windows utility called Process Monitor, which can be used to check what system calls a particular process is making. Some instructions:

    1. First, start RStudio, and open test.qmd to prepare for running your example code.
    2. Open procmon, and use the following filter to capture RStudio's R session activity:
    Screenshot 2024-05-29 at 4 14 21 PM
    1. Run the code from your example. You should see a flurry of filesystem operations in the process monitor.
    2. Use File -> Save to save the log to a file, and share that with us.
  9. self-assigned this
    on May 30, 2024
  10. marianklose commented on May 30, 2024

    @marianklose
    Author

    @kevinushey: Sure, I am happy to help. I am currently on my private windows machine at home connected to my university shared network drive. I am conducting these tests for the two extreme scenarios regarding runtime: a) local drive, no project and d) mapped / shared network drive, within project. Let me know if you also need b) and d).

    Here is a screenshot of my procmon filter (I unchecked the other filters):

    image

    I first opened the project, then the .qmd and then opened procmon and applied the filter. After applying the filter I've waited for 10 seconds before I execute the chunk. I saved the log.csv and log.PML (which I couldn't upload, let me know if you need it).

    a) local drive, no project

    d) mapped / shared network drive, within project.

    • The run time on my private PC connected to the shared network is even worse: Time difference of 56.29842 secs
    • log.csv: Logfile_case_d.CSV

    Hope that helps! Let me know if you need anything else.

  11. kevinushey commented on May 30, 2024

    @kevinushey
    Collaborator

    Thanks! This is very useful. I think this confirms some of our suspicions -- it looks like filesystem access is fairly slow on the network filesystem you're using, and since chunk execution will somewhat eagerly read and write files within the project's .Rproj.user folder, code execution gets slowed down.

    I have some changes in #14765 that may help for future builds of RStudio, but I feel like the best way to fix this would be to have some way to have the .Rproj.user folder's location customized, so you could place it on a faster filesystem (e.g. perhaps a local filesystem). This could have downsides; e.g. your session state wouldn't be preserved if you opened that project on a different machine, but that might be a tradeoff you're willing to make?

  12. marianklose commented on May 31, 2024

    @marianklose
    Author

    Thanks for getting back to me.

    it looks like filesystem access is fairly slow on the network filesystem you're using

    Indeed, it will definitely depend on the access speed to the network drive. At home I have a way slower chunk execution time (56 sec) than on my university machine (1.7 sec). On both machines I work on a mapped network drive, but apparently the access speed is higher at university. I can later also share the speed at home, but that's kind of an average writing/reading speed at the university (to and from the network drive):

    image

    I don't have a reference if that's fast or slow but this results in 1.7 sec execution time within a project.

    I have some changes in #14765 that may help for future builds of RStudio, but I feel like the best way to fix this would be to have some way to have the .Rproj.user folder's location customized, so you could place it on a faster filesystem (e.g. perhaps a local filesystem). This could have downsides; e.g. your session state wouldn't be preserved if you opened that project on a different machine, but that might be a tradeoff you're willing to make?

    Sounds reasonable to me. Personally, the potential downsides are perfectly fine with me. I mainly work with projects to use here::here() and whenever I work on packages. Preserving the session state is not really a priority to me.


    One other question: To me it makes sense that extensive reading/writing to the project files slows down the process. When comparing working with .qmd within/without projects there is a huge difference. But if I am on a slow network drive I can still feel a delay when I execute .qmd chunks without being in a project. Are there still some unneccessary reading/writing operations involved even when being outside a project?

    I was wondering that even without a project the output from a chunk (graphics, tables etc.) is being preserved even if I close the file and Rstudio and then reopen it again:

    image

    So for each chunk it needs to preserve this output somewhere, which surely involves writing to the slow network drive. I don't care about the old chunk outputs. Is there an option to turn this off and do you think this could also lead to slowing down the code execution?

  13. kevinushey commented on May 31, 2024

    @kevinushey
    Collaborator

    Are you able to try a recent daily build of RStudio? We recently implemented some optimizations that may help improve performance here:

    https://s3.amazonaws.com/rstudio-ide-build/electron/windows/RStudio-2024.07.0-daily-180.exe

    I'm also curious if using "Chunk Output in Console" makes a difference on execution performance. From the gear icon in the editor toolbar for the .Rmd document you're editing:

    Screenshot 2024-05-31 at 9 14 43 AM
  14. marianklose commented on Jun 2, 2024

    @marianklose
    Author

    I've just installed the daily build and I have the following runtime (for the .qmd inside the project on the shared network drive):

    Time difference of 21.74336 secs
    

    so it seems to improve the situation (compared to the 50+ seconds with the previous build), but 22 seconds is still pretty slow. Now using "Chunk Output in Console" speeds up the process signficantly (even when being inside a project):

    Time difference of 0.006109953 secs
    

    Thanks for pointing this out, maybe this solves already quite some speed issues. But I am wondering why there is such a significant delay when using the inline output option. There must be some kind of inefficient reading/writing process involved. This is also related to my previous question:

    I was wondering that even without a project the output from a chunk (graphics, tables etc.) is being preserved even if I close the file and Rstudio and then reopen it again

    Would it be possible to turn off preserving the chunk output for the future (so it doesn't have to be written somewhere when executing a chunk)? Maybe then we could use the inline output option (which is preferred) even with a somewhat slow network drive?

  15. ronblum commented on Jun 24, 2024

    @ronblum
    Contributor

    The latest daily builds of the release in progress, Cranberry Hibiscus 2024.07.0, have a fix for this. If anyone is willing to try it out, it would be greatly appreciated. Plese note that the daily builds are meant for testing purposes only, not production.

  16. gtritchie commented on Jun 25, 2024

    @gtritchie
    Member

    The latest daily builds of the release in progress ... have a fix for this

    Note that the fix requires configuring the project to store .Rproj.user somewhere other than the cloud drive, see #14875.

  17. marianklose commented on Jul 1, 2024

    @marianklose
    Author

    The latest daily builds of the release in progress, Cranberry Hibiscus 2024.07.0, have a fix for this. If anyone is willing to try it out, it would be greatly appreciated. Plese note that the daily builds are meant for testing purposes only, not production.

    Thanks for getting back to this. I am happy to give it a test. Without the fix (new daily build) the estimation time for the chunk inside a project is:

    Time difference of 1.708584 secs
    

    After installing the Cranberry Hibiscus 2024.07.0 daily build and adjusting the project settings (.Rproj.user moved to local C:/ drive) accordingly the estimation time is:

    Time difference of 0.219836 secs
    

    So we have a substantial improvement (nearly 10-fold) in execution times. Thanks a lot for that! It is not perfectly matching the excution time which we have when the .qmd is also located on the C:/ drive but I personally can live with that.

    Thank you!

  18. ronblum commented on Jul 9, 2024

    @ronblum
    Contributor

    @marianklose Thank you very much for testing the execution time improvement!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugneed help verifyingremote storage

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions