r-lib / rlang

Low-level API for programming with R
https://rlang.r-lib.org
Other
498 stars 136 forks source link

Add `keep_source` to `parse_exprs()` and friends #1603

Closed DavisVaughan closed 1 year ago

DavisVaughan commented 1 year ago

These call parse() which defaults to keep.source = TRUE, but you typically don't need that and it is super slow. It ends up calling srcfilecopy() which even calls getwd() internally!

bench::mark(parse(text = "x"), parse(text = "x", keep.source = F), check = F)
#> # A tibble: 2 × 6
#>   expression                              min   median `itr/sec` mem_a…¹ gc/se…²
#>   <bch:expr>                         <bch:tm> <bch:tm>     <dbl> <bch:b>   <dbl>
#> 1 parse(text = "x")                   47.53µs   51.3µs    17793.    280B    4.04
#> 2 parse(text = "x", keep.source = F)   3.01µs   3.87µs   256832.      0B   25.7 
#> # … with abbreviated variable names ¹​mem_alloc, ²​`gc/sec`

Consider defaulting keep_source to FALSE? Not sure how important the sources are in typical usage of this function.