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

Also cache whole roxygen2 example code, not just top-level expressions #607

Merged
merged 8 commits into from Feb 22, 2020

Conversation

lorenzwalthert
Copy link
Collaborator

@lorenzwalthert lorenzwalthert commented Feb 20, 2020

Closes #605. styling for fully cached expressions will be a bit slower (factor 65 instead of 80 compared to full styling), but we get large speed gains if roxygen code is not modified but any other token is modified (which is most of the time I think): here with current master:

library(magrittr)
  library(styler)
  text_long <- c(
    "#' Roxygen",
    "#' Comment",
    "#' @examples",
    "#' 1 + 1",
    "#' if (x > 4)",
    "#' bb = 3",
    "#' call(x,y=2)",
    "k <- function() {",
    "  1 + 1",
    "  if (x) {",
    "    k()",
    "  }",
    "}",
    ""
  )
  text_long_styled <- style_text(text_long)
  purrr::map_dbl(1:5,
    function(x) {
      styler:::fresh_testthat_cache()
      text_long_styled <- style_text(text_long)
      text_long_styled[13] <- "    }"
      system.time(style_text(text_long_styled))['elapsed']
  }) %>%
    mean()
#> Using cache testthat at /Users/lorenz/Library/Caches/R/R.cache/styler/testthat.
#> Using cache testthat at /Users/lorenz/Library/Caches/R/R.cache/styler/testthat.
#> Using cache testthat at /Users/lorenz/Library/Caches/R/R.cache/styler/testthat.
#> Using cache testthat at /Users/lorenz/Library/Caches/R/R.cache/styler/testthat.
#> Using cache testthat at /Users/lorenz/Library/Caches/R/R.cache/styler/testthat.
#> [1] 0.281

Created on 2020-02-22 by the reprex package (v0.3.0)

So timing is 0.281 current master and with this PR: 0.1896. The gain is larger the larger the roxgen code example block is.

@codecov-io
Copy link

codecov-io commented Feb 22, 2020

Codecov Report

Merging #607 into master will increase coverage by 0.05%.
The diff coverage is 92.3%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #607      +/-   ##
==========================================
+ Coverage   90.47%   90.53%   +0.05%     
==========================================
  Files          47       47              
  Lines        2132     2144      +12     
==========================================
+ Hits         1929     1941      +12     
  Misses        203      203
Impacted Files Coverage Δ
R/addins.R 0% <0%> (ø) ⬆️
R/utils-cache.R 100% <100%> (ø) ⬆️
R/roxygen-examples.R 96.87% <100%> (+0.87%) ⬆️
R/utils.R 82.75% <100%> (+3.44%) ⬆️
R/testing.R 78.5% <92.3%> (+0.07%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a719528...a02d590. Read the comment docs.

@lorenzwalthert lorenzwalthert merged commit 49609ab into r-lib:master Feb 22, 2020
@lorenzwalthert lorenzwalthert deleted the issue-605 branch February 22, 2020 15:51
@lorenzwalthert lorenzwalthert restored the issue-605 branch November 28, 2020 11:31
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.

styler does only cache individual top-level roxygen code examples, not whole text
2 participants