r-lib / lifecycle

Manage the life cycle of your exported functions and arguments
https://lifecycle.r-lib.org
Other
95 stars 25 forks source link

Only generate the `trace_back()` as needed #177

Closed DavisVaughan closed 12 months ago

DavisVaughan commented 1 year ago

Follow up on https://github.com/r-lib/lifecycle/pull/172

I was investigating https://github.com/tidyverse/dplyr/issues/6897 with dev lifecycle installed and discovered a lot of the remaining time spent in repeated calls to deprecate_soft() and deprecate_warn() with always = FALSE is in generating the trace_back(), which we throw away every single time except for the very first one.

I've moved the trace_back() call after our early exit, which cuts the time for deprecate_soft() in half again

# trigger it once
lifecycle::deprecate_soft("1.1.0", "fn()", "fn2()")

f <- function() {
  lifecycle::deprecate_soft("1.1.0", "fn()", "fn2()")
}
g <- function() {
  for (i in 1:1000) {
    f()
  }  
}
bench::system_time(g())

Current dev main

process    real 
  712ms   703ms

This PR

process    real 
  385ms   379ms 
lionel- commented 12 months ago

Awesome, thanks!