Skip to content

FR: Switch to yyjsonr (or similar) from jsonlite #415

@khusmann

Description

@khusmann

A big bottleneck for large dataframes in reactable is JSON conversion. Simply by switching to a faster JSON conversion package you get a massive speedup.

library(reactable)
library(tibble)


df <- tibble(
  a = 1:1e8
)

system.time(
  reactable(df)
)

Result:

   user  system elapsed 
  53.11    6.42   60.92 

Now, we monkey-patch reactable to use yyjsonr instead of jsonlite:

to_json_adapter <- function(x, ..., digits = -1, auto_unbox = TRUE) {
  result <- yyjsonr::write_json_str(
    x,
    opts = yyjsonr::opts_write_json(
      digits = digits,
      auto_unbox = auto_unbox,
      dataframe = "columns"
    )
  )
  class(result) <- "json"
  result
}
unlockBinding("toJSON", asNamespace("reactable"))
assign("toJSON", to_json_adapter, envir = asNamespace("reactable"))
lockBinding("toJSON", asNamespace("reactable"))

Re-running the same block of code:

system.time(
  reactable(df)
)

We now get:

   user  system elapsed 
   2.89    1.47    5.41 

That's a >10x speedup, just by changing the JSON library! This means you can squeeze out 10x the juice of client-side reactable before you have to upgrade to server-side rendering... that's huge.

Implementation note: we'll also want to run the faster JSON parser on the meta = argument (otherwise reactR uses slow jsonlite by default)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions