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

Feature request: getMode() as a fast shortcut for versionInfo()$mode #280

Closed
DavisVaughan opened this issue Jul 12, 2023 · 3 comments
Closed

Comments

@DavisVaughan
Copy link

DavisVaughan commented Jul 12, 2023

Similar to #279

We discovered in r-lib/lifecycle#167 that cli::num_ansi_colors() is slow when called interactively in RStudio due to rstudioapi::versionInfo() being fairly slow. versionInfo() is slow due to having to call readCitationFile(), and in cli the citation bit isn't required at all. The only things it uses are the $version and the $mode.

getVersion() gives us fast (in theory, see #279) access to $version. It would be nice to also have getMode() that cli could use to have fast access to the $mode.

library(rstudioapi)

bench::mark(
  .Call("rs_rstudioProgramMode", PACKAGE = "(embedding)"),
  versionInfo()$mode
)
# A tibble: 2 × 13
  expression      min median `itr/sec` mem_alloc `gc/sec` n_itr  n_gc total_time result memory    
  <bch:expr>    <bch> <bch:>     <dbl> <bch:byt>    <dbl> <int> <dbl>   <bch:tm> <list> <list>    
1 ".Call(\"rs_… 328ns  410ns  2298553.        0B     0    10000     0     4.35ms <chr>  <Rprofmem>
2 "versionInfo… 375µs  386µs     2515.    20.6KB     8.27  1216     4   483.42ms <chr>  <Rprofmem>
# ℹ 2 more variables: time <list>, gc <list>
@TimTaylor
Copy link

TimTaylor commented Oct 16, 2024

@kevinushey - Sorry to be that person 😬 but do we think this and #279 are going to be implemented in the foreseeable future? Experiencing very slow (relative) tibble printing for some things which I think is again down to cli::num_ansi_colors.

@kevinushey
Copy link
Contributor

Done now; on the way to CRAN.

@TimTaylor
Copy link

⭐ Thank you!

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

No branches or pull requests

3 participants