rstudio / htmltools

Tools for HTML generation and output
https://rstudio.github.io/htmltools/
215 stars 68 forks source link

Improve performance of tags functions #414

Open mgirlich opened 11 months ago

mgirlich commented 11 months ago

Functions like tags$tr() can easily be a little faster.

library(htmltools)

set.seed(1)
n <- 50e3
data <- vroom::gen_character(n)

f <- function(data) {
  for (i in seq_along(data)) {
    tags$tr(data[[i]])
  }
}

bench::mark(f(data))

# before
# # A tibble: 1 × 13
#   expression      min   median `itr/sec` mem_alloc `gc/sec` n_itr  n_gc total_time
#   <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl> <int> <dbl>   <bch:tm>
# 1 f(data)       1.37s    1.37s     0.730    41.2KB     27.8     1    38      1.37s

# after
# # A tibble: 1 × 13
#   expression      min   median `itr/sec` mem_alloc `gc/sec` n_itr  n_gc total_time
#   <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl> <int> <dbl>   <bch:tm>
# 1 f(data)       830ms    830ms      1.20    30.1KB     30.1     1    25      830ms