Skip to content

Commit 4905fc5

Browse files
Merge pull request #684 from lorenzwalthert/issue-680
- Add one more benchmark plot on recording for cache only (#680).
2 parents c50338f + 5f34131 commit 4905fc5

File tree

3 files changed

+93
-16
lines changed

3 files changed

+93
-16
lines changed

.github/workflows/benchmarking.yaml

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
1+
name: Continuous Benchmarks
12
on:
23
push:
34
branches:
45
- master
56
pull_request:
67
branches:
78
- master
8-
9-
name: Continuous Benchmarks
10-
119
jobs:
1210
build:
13-
runs-on: macOS-latest
11+
runs-on: ${{ matrix.config.os }}
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
config:
16+
- {os: ubuntu-18.04, r: '4.0.0', rspm: 'https://packagemanager.rstudio.com/all/__linux__/bionic/291'}
17+
18+
env:
19+
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
20+
RSPM: ${{ matrix.config.rspm }}
21+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
1422
steps:
1523
- name: Checkout repo
1624
with:
1725
fetch-depth: 0
1826
uses: actions/checkout@master
27+
- name: Set up git user
28+
run: |
29+
git config --local user.name "GitHub Actions"
30+
git config --local user.email "[email protected]"
1931
- name: Ensure base branch is fetched
2032
if: ${{ github.event_name == 'pull_request' }}
2133
run: git branch $GITHUB_BASE_REF remotes/origin/$GITHUB_BASE_REF; git branch
@@ -27,15 +39,22 @@ jobs:
2739
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
2840
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
2941
shell: Rscript {0}
30-
3142
- name: Cache R packages
3243
if: runner.os != 'Windows'
3344
uses: actions/cache@v1
3445
with:
3546
path: ${{ env.R_LIBS_USER }}
36-
key: ${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
37-
restore-keys: ${{ hashFiles('.github/R-version') }}-1-
38-
47+
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-3-${{ hashFiles('.github/depends.Rds') }}
48+
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-3-
49+
- name: Install system dependencies
50+
if: runner.os == 'Linux'
51+
env:
52+
RHUB_PLATFORM: linux-x86_64-ubuntu-gcc
53+
run: |
54+
Rscript -e "remotes::install_github('r-hub/sysreqs')"
55+
sysreqs=$(Rscript -e "cat(sysreqs::sysreq_commands('DESCRIPTION'))")
56+
sudo -s eval "$sysreqs"
57+
sudo apt-get install libcurl4-openssl-dev libgit2-dev
3958
- name: Install dependencies
4059
run: |
4160
Rscript -e "install.packages(c('gert', 'ggplot2', 'purrr'))" -e "remotes::install_deps(dependencies = TRUE); remotes::install_github('r-lib/bench')"
@@ -48,6 +67,10 @@ jobs:
4867
path: bench/sources/here
4968
- name: Fetch existing benchmarks
5069
run: Rscript -e 'rlang::with_handlers(bench::cb_fetch(), error = function(e) paste("Could not fetch benchmarks, skipping. The error was", conditionMessage(e)))'
70+
- name: Prepare PR comment
71+
run: |
72+
mkdir -p bench/pr-comment
73+
echo 'Here is how the current PR would change benchmark results:\n' > bench/pr-comment/info.txt
5174
- name: Run benchmarks
5275
run: Rscript -e 'bench::cb_run()'
5376
- name: Show benchmarks
@@ -59,3 +82,13 @@ jobs:
5982
- name: Push benchmarks
6083
if: ${{ github.event_name == 'push' }}
6184
run: Rscript -e "bench::cb_push()"
85+
- uses: actions/upload-artifact@v1
86+
with:
87+
name: results
88+
path: bench/pr-comment
89+
- uses: actions/download-artifact@v1
90+
with:
91+
name: results
92+
- name: comment PR
93+
#uses: machine-learning-apps/pr-comment@master
94+
run: cat bench/pr-comment/info.txt

bench/01-declarations.R

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@ plot_against_base <- function(new_bm,
1717
if (any(commit_is_reference) && Sys.getenv("GITHUB_BASE_REF") != "") {
1818
# if a pull request
1919
reference <- bm[commit_is_reference, "benchmarks"][[1]][[1]]
20-
if (nrow(reference) > 0 && "name" %in% names(reference)) {
21-
reference <- reference %>%
22-
dplyr::filter(.data$name %in% !!name)
20+
# if benchmark exists in base branch
21+
reference <- reference %>%
22+
dplyr::filter(.data$name %in% !!name)
23+
if (nrow(reference) > 0) {
24+
# if benchmark exists in base branch
2325
reference$expression <- bench:::new_bench_expr(Sys.getenv("GITHUB_BASE_REF"))
2426
new_bm <- dplyr::bind_rows(reference, new_bm)
27+
stopifnot(nrow(new_bm) == 2)
28+
diff_in_percent <- round(100 * diff(new_bm$p50) / new_bm$p50[1])
29+
pr_comment <- glue::glue("* {name}: {new_bm$p50[1]} -> {new_bm$p50[2]} ({diff_in_percent}%)\n")
30+
cat(pr_comment, file = "pr-comment/info.txt", append = TRUE)
2531
}
2632
}
2733
new_bm$branch <- factor(new_bm$expression)

bench/02-basic.R

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,69 @@ library(magrittr)
66
path <- "sources/here"
77
dir.create("plots")
88
cache_clear(ask = FALSE)
9-
cache_activate()
10-
cache_info()
9+
1110

1211
marker <- purrr::partial(
1312
bench::mark,
14-
min_iterations = 20,
13+
min_iterations = 25,
1514
check = FALSE,
1615
filter_gc = FALSE,
1716
memory = TRUE # skip uncached first round
1817
)
1918

19+
# basically applying cache only
20+
# No transformer is ran ever because all code is already compliant.
21+
cache_activate()
22+
cache_info()
23+
Sys.sleep(3) # make system more idle
2024
with_cache <- marker(
21-
with_cache = {
25+
cache_appyling = {
2226
style_pkg(path, filetype = c("R", "rmd"))
2327
}
2428
)
29+
30+
# basically recording cache only
31+
# transformers are always ran on expressions that were not compliant with the
32+
# style guide (some but not all expressions are)
33+
Sys.sleep(3) # make system more idle
34+
with_cache <- marker(
35+
cache_recording = {
36+
cat(
37+
bench::system_time(gert::git_reset_hard(repo = path))[["process"]],
38+
sep = "\n",
39+
file = "timing-reset",
40+
append = TRUE
41+
)
42+
style_pkg(path, filetype = c("R", "rmd"))
43+
}
44+
)
45+
2546
cache_info()
47+
48+
# cache turned off
49+
# recording and applying, transformers always ran on all expressions.
2650
gert::git_reset_hard(repo = path)
2751
cache_deactivate()
28-
52+
time_for_git_reset <- as.numeric(readLines("timing-reset"))[-1]
53+
cat(
54+
"Waiting ",
55+
round(mean(time_for_git_reset), 3),
56+
" seconds on average to simulate git reset. That way, `without_cache` and ",
57+
"`cache_recording` are comparable. The 95% interval for reset are (",
58+
round(quantile(time_for_git_reset, 0.025), 3), ", ",
59+
round(quantile(time_for_git_reset, 0.975), 3), ").",
60+
sep = ""
61+
)
62+
mean_time_for_git_reset <- mean(time_for_git_reset)
63+
Sys.sleep(3) # make system more idle
2964
without_cache <- marker(
3065
without_cache = {
66+
Sys.sleep(mean_time_for_git_reset)
3167
style_pkg(path, filetype = c("R", "rmd"))
3268
}
3369
)
70+
71+
# visualize results
3472
latest_bm <- bench::cb_read()$benchmarks[[1]]
3573
split(latest_bm, latest_bm$name) %>%
3674
purrr::imap(plot_against_base)

0 commit comments

Comments
 (0)