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

Add one more benchmark plot on recording for cache only #684

Merged
merged 43 commits into from
Oct 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
88e8d7a
add third case, only recording
lorenzwalthert Oct 21, 2020
7f360f1
simulate reset
lorenzwalthert Oct 21, 2020
a079094
drop first reset, as first run is not recorded
lorenzwalthert Oct 22, 2020
310e2cb
force more idle time
lorenzwalthert Oct 22, 2020
47e57a7
more iterations
lorenzwalthert Oct 22, 2020
799e9fe
get rid of the 0.012 seconds a reset takes on average.
lorenzwalthert Oct 23, 2020
07d3d67
Revert "get rid of the 0.012 seconds a reset takes on average."
lorenzwalthert Oct 23, 2020
11b1eab
pre-compute mean
lorenzwalthert Oct 23, 2020
a878874
Revert "pre-compute mean"
lorenzwalthert Oct 23, 2020
f87eb0e
Revert "Revert "pre-compute mean""
lorenzwalthert Oct 23, 2020
d947c42
lock R and package versions for more stability
lorenzwalthert Oct 24, 2020
94770cd
switch to ubuntu from macOS
lorenzwalthert Oct 24, 2020
8e535d6
parsing error
lorenzwalthert Oct 24, 2020
47ffeab
install system dependencies
lorenzwalthert Oct 24, 2020
56fa1cd
don't cache deps
lorenzwalthert Oct 24, 2020
7a37d71
setup git user
lorenzwalthert Oct 25, 2020
391f5d5
set up git user again
lorenzwalthert Oct 25, 2020
ba69805
drop all but benchmarks runs
lorenzwalthert Oct 25, 2020
3f3b612
fix indent
lorenzwalthert Oct 25, 2020
d2a2034
install more system deps
lorenzwalthert Oct 25, 2020
c30eb62
sudo apt install
lorenzwalthert Oct 25, 2020
4a94166
actually use RStudio Package Manager
lorenzwalthert Oct 25, 2020
c7c7dfd
set RStudio package manager globally
lorenzwalthert Oct 25, 2020
b60d595
more close to r cmd check template
lorenzwalthert Oct 25, 2020
7f1e9fb
specify runs-on key
lorenzwalthert Oct 25, 2020
6308df5
specify R version
lorenzwalthert Oct 25, 2020
b1b646b
Revert "specify R version"
lorenzwalthert Oct 25, 2020
2559170
use all, not cran
lorenzwalthert Oct 25, 2020
a2f2d2d
cache deps
lorenzwalthert Oct 25, 2020
320e05e
more sys deps
lorenzwalthert Oct 25, 2020
dc9026e
bump to see if cache works
lorenzwalthert Oct 25, 2020
a7ffcf9
comment on PR
lorenzwalthert Oct 25, 2020
bb72225
debug
lorenzwalthert Oct 25, 2020
1a59a8d
more debugging
lorenzwalthert Oct 25, 2020
f1e8cf3
down and upload
lorenzwalthert Oct 25, 2020
bb9db83
move closer to the example
lorenzwalthert Oct 25, 2020
7cb2ff5
create directory
lorenzwalthert Oct 25, 2020
c56e232
fix file
lorenzwalthert Oct 25, 2020
0a1ccfd
remove unused env variable
lorenzwalthert Oct 25, 2020
aa99a4c
don't comment, only print in log
lorenzwalthert Oct 25, 2020
8aefa1e
Revert "drop all but benchmarks runs"
lorenzwalthert Oct 25, 2020
2ed7b0e
scale up again
lorenzwalthert Oct 25, 2020
5f34131
see if we can get rid of extra check
lorenzwalthert Oct 25, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 41 additions & 8 deletions .github/workflows/benchmarking.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
name: Continuous Benchmarks
on:
push:
branches:
- master
pull_request:
branches:
- master

name: Continuous Benchmarks

jobs:
build:
runs-on: macOS-latest
runs-on: ${{ matrix.config.os }}
strategy:
fail-fast: false
matrix:
config:
- {os: ubuntu-18.04, r: '4.0.0', rspm: 'https://packagemanager.rstudio.com/all/__linux__/bionic/291'}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout repo
with:
fetch-depth: 0
uses: actions/checkout@master
- name: Set up git user
run: |
git config --local user.name "GitHub Actions"
git config --local user.email "[email protected]"
- name: Ensure base branch is fetched
if: ${{ github.event_name == 'pull_request' }}
run: git branch $GITHUB_BASE_REF remotes/origin/$GITHUB_BASE_REF; git branch
Expand All @@ -27,15 +39,22 @@ jobs:
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}

- name: Cache R packages
if: runner.os != 'Windows'
uses: actions/cache@v1
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ hashFiles('.github/R-version') }}-1-

key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-3-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-3-
- name: Install system dependencies
if: runner.os == 'Linux'
env:
RHUB_PLATFORM: linux-x86_64-ubuntu-gcc
run: |
Rscript -e "remotes::install_github('r-hub/sysreqs')"
sysreqs=$(Rscript -e "cat(sysreqs::sysreq_commands('DESCRIPTION'))")
sudo -s eval "$sysreqs"
sudo apt-get install libcurl4-openssl-dev libgit2-dev
- name: Install dependencies
run: |
Rscript -e "install.packages(c('gert', 'ggplot2', 'purrr'))" -e "remotes::install_deps(dependencies = TRUE); remotes::install_github('r-lib/bench')"
Expand All @@ -48,6 +67,10 @@ jobs:
path: bench/sources/here
- name: Fetch existing benchmarks
run: Rscript -e 'rlang::with_handlers(bench::cb_fetch(), error = function(e) paste("Could not fetch benchmarks, skipping. The error was", conditionMessage(e)))'
- name: Prepare PR comment
run: |
mkdir -p bench/pr-comment
echo 'Here is how the current PR would change benchmark results:\n' > bench/pr-comment/info.txt
- name: Run benchmarks
run: Rscript -e 'bench::cb_run()'
- name: Show benchmarks
Expand All @@ -59,3 +82,13 @@ jobs:
- name: Push benchmarks
if: ${{ github.event_name == 'push' }}
run: Rscript -e "bench::cb_push()"
- uses: actions/upload-artifact@v1
with:
name: results
path: bench/pr-comment
- uses: actions/download-artifact@v1
with:
name: results
- name: comment PR
#uses: machine-learning-apps/pr-comment@master
run: cat bench/pr-comment/info.txt
12 changes: 9 additions & 3 deletions bench/01-declarations.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@ plot_against_base <- function(new_bm,
if (any(commit_is_reference) && Sys.getenv("GITHUB_BASE_REF") != "") {
# if a pull request
reference <- bm[commit_is_reference, "benchmarks"][[1]][[1]]
if (nrow(reference) > 0 && "name" %in% names(reference)) {
reference <- reference %>%
dplyr::filter(.data$name %in% !!name)
# if benchmark exists in base branch
reference <- reference %>%
dplyr::filter(.data$name %in% !!name)
if (nrow(reference) > 0) {
# if benchmark exists in base branch
reference$expression <- bench:::new_bench_expr(Sys.getenv("GITHUB_BASE_REF"))
new_bm <- dplyr::bind_rows(reference, new_bm)
stopifnot(nrow(new_bm) == 2)
diff_in_percent <- round(100 * diff(new_bm$p50) / new_bm$p50[1])
pr_comment <- glue::glue("* {name}: {new_bm$p50[1]} -> {new_bm$p50[2]} ({diff_in_percent}%)\n")
cat(pr_comment, file = "pr-comment/info.txt", append = TRUE)
}
}
new_bm$branch <- factor(new_bm$expression)
Expand Down
48 changes: 43 additions & 5 deletions bench/02-basic.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,69 @@ library(magrittr)
path <- "sources/here"
dir.create("plots")
cache_clear(ask = FALSE)
cache_activate()
cache_info()


marker <- purrr::partial(
bench::mark,
min_iterations = 20,
min_iterations = 25,
check = FALSE,
filter_gc = FALSE,
memory = TRUE # skip uncached first round
)

# basically applying cache only
# No transformer is ran ever because all code is already compliant.
cache_activate()
cache_info()
Sys.sleep(3) # make system more idle
with_cache <- marker(
with_cache = {
cache_appyling = {
style_pkg(path, filetype = c("R", "rmd"))
}
)

# basically recording cache only
# transformers are always ran on expressions that were not compliant with the
# style guide (some but not all expressions are)
Sys.sleep(3) # make system more idle
with_cache <- marker(
cache_recording = {
cat(
bench::system_time(gert::git_reset_hard(repo = path))[["process"]],
sep = "\n",
file = "timing-reset",
append = TRUE
)
style_pkg(path, filetype = c("R", "rmd"))
}
)

cache_info()

# cache turned off
# recording and applying, transformers always ran on all expressions.
gert::git_reset_hard(repo = path)
cache_deactivate()

time_for_git_reset <- as.numeric(readLines("timing-reset"))[-1]
cat(
"Waiting ",
round(mean(time_for_git_reset), 3),
" seconds on average to simulate git reset. That way, `without_cache` and ",
"`cache_recording` are comparable. The 95% interval for reset are (",
round(quantile(time_for_git_reset, 0.025), 3), ", ",
round(quantile(time_for_git_reset, 0.975), 3), ").",
sep = ""
)
mean_time_for_git_reset <- mean(time_for_git_reset)
Sys.sleep(3) # make system more idle
without_cache <- marker(
without_cache = {
Sys.sleep(mean_time_for_git_reset)
style_pkg(path, filetype = c("R", "rmd"))
}
)

# visualize results
latest_bm <- bench::cb_read()$benchmarks[[1]]
split(latest_bm, latest_bm$name) %>%
purrr::imap(plot_against_base)