Skip to content

JSON (de)serialization performance #29

Open

Description

@JosiahParry

Given that there is a real effort for a rethinking of plumber in this package, I would love for this team to consider ways to improve the performance of json serialization and deserialization. While jsonlite is a tried and true method for parsing and serializing json, the R community has created far more performant alternatives. Most notably, I believe these are yyjsonr, RcppSimdJson, and jsonify.

Below I compare the use of yyjsonr as an alternative to jsonlite in the existing {plumber} package as motivation.

Serialization

For smaller data, jsonlite is a very solid performer. However, as the size of the object that we need to serialize grows, its performance gets outshined.

Below is a the output of bench::press() where the penguins dataset (shouts out R 4.5) is sampled 10, 100, 10_000, 100_000, and 1_000_000, times. Each sample is done 25 times.

Once we hit ~10,000 the difference between the two packages becomes quite stark:

expression n niter min median itr/sec mem_alloc gc/sec n_itr
jsonlite 10 25 3.96ms 4.56ms 165.1419049 50.38KB 0.0000000 25
yyjsonr 10 25 3.24ms 3.34ms 295.1780670 50.02KB 12.2990861 24
jsonlite 100 25 4.38ms 4.84ms 204.9297927 62.88KB 0.0000000 25
yyjsonr 100 25 3.42ms 3.69ms 269.8536134 61.67KB 0.0000000 25
jsonlite 1000 25 7.61ms 8.07ms 123.3828804 190.94KB 0.0000000 25
yyjsonr 1000 25 5.34ms 5.5ms 177.4808128 178.15KB 0.0000000 25
jsonlite 10000 25 42.59ms 45.1ms 22.0107531 1.45MB 0.9171147 24
yyjsonr 10000 25 26.12ms 27.19ms 36.5426133 1.31MB 1.5226089 24
jsonlite 100000 25 458.22ms 477.87ms 2.0399509 14.13MB 3.0599263 10
yyjsonr 100000 25 225.47ms 255.6ms 3.9622886 12.69MB 3.6574972 13
jsonlite 1000000 25 5.71s 6.18s 0.1617885 141.83MB 0.1617885 25
yyjsonr 1000000 25 2.45s 2.73s 0.3680920 126.49MB 0.3680920 25

Deserialization

For deserialization, I've do the same thing but for samples of 10, 100, 10_000, and 100_000.

Image
expression n niter min median itr/sec mem_alloc gc/sec n_itr
jsonlite 10 25 5.29ms 5.99ms 162.3904318 51.07KB 0.0000000 25
yyjsonr 10 25 5.09ms 5.42ms 184.3409827 51KB 0.0000000 25
jsonlite 100 25 6.46ms 7.17ms 139.5966556 115.97KB 0.0000000 25
yyjsonr 100 25 5.65ms 6.1ms 163.2072773 114.72KB 0.0000000 25
jsonlite 1000 25 16.49ms 17.3ms 57.8857935 705.23KB 0.0000000 25
yyjsonr 1000 25 9.4ms 10.2ms 96.3886582 688.04KB 0.0000000 25
jsonlite 10000 25 108.73ms 113.81ms 8.6441140 6.92MB 0.3601714 24
yyjsonr 10000 25 44.97ms 46.59ms 20.8253656 6.38MB 0.8677236 24
jsonlite 100000 25 1.09s 1.16s 0.8444085 80.15MB 0.1151466 22
yyjsonr 100000 25 409.87ms 435.56ms 2.2831995 63.51MB 0.3113454 22

Repro code

If you've made it this far, I would like to say Thank You For Coming To My TED Talk™. I think quality of life enhancements like this can make R seem like an even more viable tool for backend development. I'd like to prove all of the haters wrong.

router <- callr::r_bg(\() {
  library(plumber)

  get_penguins <- function(n = 100) {
    np <- nrow(penguins)
    idx <- sample(1:np, n, replace = TRUE)
    penguins[idx, ]
  }

  read_penguins <- function(req) {
    body <- req$body
    as.numeric(Sys.time() - req$STARTED_AT)
  }

  yy_serializer <- plumber:::serializer_content_type(
    "application/json",
    function(val) {
      yyjsonr::write_json_str(val)
    }
  )
  yy_parser <- function(...) {
    function(value, content_type = "application/json", ...) {
      yyjsonr::read_json_raw(value)
    }
  }

  register_parser("yyjson", yy_parser, fixed = "application/json")

  router <- pr() |>
    pr_get("/serialize", get_penguins) |>
    pr_get(
      "/serialize-yy",
      get_penguins,
      serializer = yy_serializer
    ) |>
    pr_post(
      "/deserialize",
      read_penguins,
    ) |>
    pr_post("/deserialize-yy", read_penguins, parser = "yyjson") |>
    pr_filter("set_time", function(req) {
      req$STARTED_AT <- Sys.time()
      forward()
    })

  pr_run(router, port = "3000")
})


get_pengos <- function(n) {
  start <- Sys.time()
  httr2::request("http://127.0.0.1:3000/serialize?") |>
    httr2::req_url_query(n = n) |>
    httr2::req_perform()
  Sys.time() - start
}

get_pengos_yy <- function(n) {
  start <- Sys.time()
  httr2::request("http://127.0.0.1:3000/serialize-yy?") |>
    httr2::req_url_query(n = n) |>
    httr2::req_perform()
  Sys.time() - start
}


benches <- bench::press(
  n = c(1e1, 1e2, 1e3, 1e4, 1e5, 1e6),
  niter = 25,
  {
    bench::mark(
      jsonlite = get_pengos(n),
      yyjsonr = get_pengos_yy(n),
      iterations = niter,
      check = FALSE
    )
  }
)

# plot(benches)


# benches[,1:9] |> 
#   dplyr::mutate(n = format(n, scientific = F)) |> 
#   knitr::kable() |> 
#   clipr::write_clip()


deserialize <- function(n) {
  np <- nrow(penguins)
  idx <- sample(1:np, n, replace = TRUE)
  httr2::request("http://127.0.0.1:3000/deserialize") |>
    httr2::req_body_json(penguins[idx, ]) |>
    httr2::req_perform()
}


deserialize_yy <- function(n) {
  np <- nrow(penguins)
  idx <- sample(1:np, n, replace = TRUE)
  httr2::request("http://127.0.0.1:3000/deserialize-yy") |>
    httr2::req_body_json(penguins[idx, ]) |>
    httr2::req_perform()
}


benches_de <- bench::press(
  n = c(1e1, 1e2, 1e3, 1e4, 1e5),
  niter = 25,
  {
    bench::mark(
      jsonlite = deserialize(n),
      yyjsonr = deserialize_yy(n),
      iterations = niter,
      check = FALSE
    )
  }
)


# plot(benches_de)
# benches_de[,1:9] |> 
#   dplyr::mutate(n = format(n, scientific = F)) |> 
#   knitr::kable() |> 
#   clipr::write_clip()

Activity

  1. thomasp85 commented on Apr 22, 2025

    @thomasp85
    Collaborator

    I'm not completely against it and tbh have contemplated it more than one time. The current blocker is that yyjsonr seems to be stale in it's development with a bunch of issues reported by CRAN that has been lingering (not throwing shade at the developer - we all have a lot to do). Anyway, for something this foundational I'd be reluctant to depend on something that isn't sure to stay on CRAN.

    For the time being you can very easily add your own serializers to plumber2 but I'll leave the issue open as I might eventually switch over

  2. schloerke commented on Apr 22, 2025

    @schloerke
    Collaborator

    {yyjsonr} CRAN checks


    CRAN Package Check Results for Package yyjsonr

    Last updated on 2025-04-22 18:50:33 CEST.

    Flavor Version Tinstall Tcheck Ttotal Status Flags
    r-devel-linux-x86_64-debian-clang 0.1.20 20.37 32.71 53.08 NOTE  
    r-devel-linux-x86_64-debian-gcc 0.1.20 21.73 25.28 47.01 NOTE  
    r-devel-linux-x86_64-fedora-clang 0.1.20     82.01 NOTE  
    r-devel-linux-x86_64-fedora-gcc 0.1.20     122.30 NOTE  
    r-devel-windows-x86_64 0.1.20 30.00 64.00 94.00 NOTE  
    r-patched-linux-x86_64 0.1.20 28.25 31.78 60.03 NOTE  
    r-release-linux-x86_64 0.1.20 27.99 32.08 60.07 NOTE  
    r-release-macos-arm64 0.1.20     39.00 NOTE  
    r-release-macos-x86_64 0.1.20     75.00 NOTE  
    r-release-windows-x86_64 0.1.20 31.00 63.00 94.00 NOTE  
    r-oldrel-macos-arm64 0.1.20     43.00 OK  
    r-oldrel-macos-x86_64 0.1.20     54.00 OK  
    r-oldrel-windows-x86_64 0.1.20 33.00 69.00 102.00 OK  

    Additional issues

    rchk

    Check Details

    Version: 0.1.20
    Check: compiled code
    Result: NOTE 

      File ‘yyjsonr/libs/yyjsonr.so’:
        Found non-API calls to R: ‘R_lsInternal’, ‘SETLENGTH’,
          ‘SET_GROWABLE_BIT’, ‘SET_TRUELENGTH’
      
      Compiled code should not call non-API entry points in R.
      
      See ‘Writing portable packages’ in the ‘Writing R Extensions’ manual,
      and section ‘Moving into C API compliance’ for issues with the use of
      non-API entry points.
    

    Flavors: r-devel-linux-x86_64-debian-clang, r-devel-linux-x86_64-debian-gcc, r-devel-linux-x86_64-fedora-clang, r-devel-linux-x86_64-fedora-gcc, r-patched-linux-x86_64, r-release-linux-x86_64, r-release-macos-arm64, r-release-macos-x86_64

    Version: 0.1.20
    Check: compiled code
    Result: NOTE 

      File 'yyjsonr/libs/x64/yyjsonr.dll':
        Found non-API calls to R: 'R_lsInternal', 'SETLENGTH',
          'SET_GROWABLE_BIT', 'SET_TRUELENGTH'
      
      Compiled code should not call non-API entry points in R.
      
      See 'Writing portable packages' in the 'Writing R Extensions' manual,
      and section 'Moving into C API compliance' for issues with the use of
      non-API entry points.
    </span>Flavors:<span> </span><a href="https://www.r-project.org/nosvn/R.check/r-devel-windows-x86_64/yyjsonr-00check.html" style="background: white; color: blue;"><span class="CRAN" style="color: rgb(39, 109, 195); text-decoration: underline;">r-devel-windows-x86_64</span></a>,<span> </span><a href="https://www.r-project.org/nosvn/R.check/r-release-windows-x86_64/yyjsonr-00check.html" style="background: white; color: blue;"><span class="CRAN" style="color: rgb(39, 109, 195); text-decoration: underline;">r-release-windows-x86_64</span></a></p>CRAN Package Check Results for Package [yyjsonr](https://cran.r-project.org/web/packages/yyjsonr/index.html)
    Last updated on 2025-04-22 18:50:33 CEST.
    
    Flavor	Version	Tinstall	Tcheck	Ttotal	Status	Flags
    [r-devel-linux-x86_64-debian-clang](https://cran.r-project.org/web/checks/check_flavors.html#r-devel-linux-x86_64-debian-clang)	0.1.20	20.37	32.71	53.08	[NOTE](https://www.r-project.org/nosvn/R.check/r-devel-linux-x86_64-debian-clang/yyjsonr-00check.html)	
    [r-devel-linux-x86_64-debian-gcc](https://cran.r-project.org/web/checks/check_flavors.html#r-devel-linux-x86_64-debian-gcc)	0.1.20	21.73	25.28	47.01	[NOTE](https://www.r-project.org/nosvn/R.check/r-devel-linux-x86_64-debian-gcc/yyjsonr-00check.html)	
    [r-devel-linux-x86_64-fedora-clang](https://cran.r-project.org/web/checks/check_flavors.html#r-devel-linux-x86_64-fedora-clang)	0.1.20			82.01	[NOTE](https://www.r-project.org/nosvn/R.check/r-devel-linux-x86_64-fedora-clang/yyjsonr-00check.html)	
    [r-devel-linux-x86_64-fedora-gcc](https://cran.r-project.org/web/checks/check_flavors.html#r-devel-linux-x86_64-fedora-gcc)	0.1.20			122.30	[NOTE](https://www.r-project.org/nosvn/R.check/r-devel-linux-x86_64-fedora-gcc/yyjsonr-00check.html)	
    [r-devel-windows-x86_64](https://cran.r-project.org/web/checks/check_flavors.html#r-devel-windows-x86_64)	0.1.20	30.00	64.00	94.00	[NOTE](https://www.r-project.org/nosvn/R.check/r-devel-windows-x86_64/yyjsonr-00check.html)	
    [r-patched-linux-x86_64](https://cran.r-project.org/web/checks/check_flavors.html#r-patched-linux-x86_64)	0.1.20	28.25	31.78	60.03	[NOTE](https://www.r-project.org/nosvn/R.check/r-patched-linux-x86_64/yyjsonr-00check.html)	
    [r-release-linux-x86_64](https://cran.r-project.org/web/checks/check_flavors.html#r-release-linux-x86_64)	0.1.20	27.99	32.08	60.07	[NOTE](https://www.r-project.org/nosvn/R.check/r-release-linux-x86_64/yyjsonr-00check.html)	
    [r-release-macos-arm64](https://cran.r-project.org/web/checks/check_flavors.html#r-release-macos-arm64)	0.1.20			39.00	[NOTE](https://www.r-project.org/nosvn/R.check/r-release-macos-arm64/yyjsonr-00check.html)	
    [r-release-macos-x86_64](https://cran.r-project.org/web/checks/check_flavors.html#r-release-macos-x86_64)	0.1.20			75.00	[NOTE](https://www.r-project.org/nosvn/R.check/r-release-macos-x86_64/yyjsonr-00check.html)	
    [r-release-windows-x86_64](https://cran.r-project.org/web/checks/check_flavors.html#r-release-windows-x86_64)	0.1.20	31.00	63.00	94.00	[NOTE](https://www.r-project.org/nosvn/R.check/r-release-windows-x86_64/yyjsonr-00check.html)	
    [r-oldrel-macos-arm64](https://cran.r-project.org/web/checks/check_flavors.html#r-oldrel-macos-arm64)	0.1.20			43.00	[OK](https://www.r-project.org/nosvn/R.check/r-oldrel-macos-arm64/yyjsonr-00check.html)	
    [r-oldrel-macos-x86_64](https://cran.r-project.org/web/checks/check_flavors.html#r-oldrel-macos-x86_64)	0.1.20			54.00	[OK](https://www.r-project.org/nosvn/R.check/r-oldrel-macos-x86_64/yyjsonr-00check.html)	
    [r-oldrel-windows-x86_64](https://cran.r-project.org/web/checks/check_flavors.html#r-oldrel-windows-x86_64)	0.1.20	33.00	69.00	102.00	[OK](https://www.r-project.org/nosvn/R.check/r-oldrel-windows-x86_64/yyjsonr-00check.html)	
    [Additional issues](https://cran.r-project.org/web/checks/check_issue_kinds.html)
    [rchk](https://raw.githubusercontent.com/kalibera/cran-checks/master/rchk/results/yyjsonr.out)
    
    Check Details
    Version: 0.1.20
    Check: compiled code
    Result: NOTE 
      File ‘yyjsonr/libs/yyjsonr.so’:
        Found non-API calls to R: ‘R_lsInternal’, ‘SETLENGTH’,
          ‘SET_GROWABLE_BIT’, ‘SET_TRUELENGTH’
      
      Compiled code should not call non-API entry points in R.
      
      See ‘Writing portable packages’ in the ‘Writing R Extensions’ manual,
      and section ‘Moving into C API compliance’ for issues with the use of
      non-API entry points.
    Flavors: [r-devel-linux-x86_64-debian-clang](https://www.r-project.org/nosvn/R.check/r-devel-linux-x86_64-debian-clang/yyjsonr-00check.html), [r-devel-linux-x86_64-debian-gcc](https://www.r-project.org/nosvn/R.check/r-devel-linux-x86_64-debian-gcc/yyjsonr-00check.html), [r-devel-linux-x86_64-fedora-clang](https://www.r-project.org/nosvn/R.check/r-devel-linux-x86_64-fedora-clang/yyjsonr-00check.html), [r-devel-linux-x86_64-fedora-gcc](https://www.r-project.org/nosvn/R.check/r-devel-linux-x86_64-fedora-gcc/yyjsonr-00check.html), [r-patched-linux-x86_64](https://www.r-project.org/nosvn/R.check/r-patched-linux-x86_64/yyjsonr-00check.html), [r-release-linux-x86_64](https://www.r-project.org/nosvn/R.check/r-release-linux-x86_64/yyjsonr-00check.html), [r-release-macos-arm64](https://www.r-project.org/nosvn/R.check/r-release-macos-arm64/yyjsonr-00check.html), [r-release-macos-x86_64](https://www.r-project.org/nosvn/R.check/r-release-macos-x86_64/yyjsonr-00check.html)
    
    Version: 0.1.20
    Check: compiled code
    Result: NOTE 
      File 'yyjsonr/libs/x64/yyjsonr.dll':
        Found non-API calls to R: 'R_lsInternal', 'SETLENGTH',
          'SET_GROWABLE_BIT', 'SET_TRUELENGTH'
      
      Compiled code should not call non-API entry points in R.
      
      See 'Writing portable packages' in the 'Writing R Extensions' manual,
      and section 'Moving into C API compliance' for issues with the use of
      non-API entry points.
    

    Flavors: r-devel-windows-x86_64, r-release-windows-x86_64

  3. JosiahParry commented on Apr 22, 2025

    @JosiahParry
    Author

    Thanks both for listening to the TED Talk™! I don't think that yyjsonr must be the solution. But I did want to create some evidence towards a more performant alternative.

    Thanks again for all of your work and I'm excited to give it a try :)

  4. jd4ds commented on Jun 3, 2025

    @jd4ds

    The issues described in yyjsonr should have been addressed in the latest CRAN release: coolbutuseless/yyjsonr#62.

  5. jrosell commented on Jun 6, 2025

    @jrosell

    @thomasp85 looking at @JosiahParry {plumber} code, I wonder how one could have the set_time pr_filter to and the req$STARTED_AT of the first loaded route for {plumber2}. Is there a way to specify the order of the routes and have a api_any run the first one? An example in the migration docs could help. I think it's a good way for measuring reading performace.

  6. thomasp85 commented on Jun 6, 2025

    @thomasp85
    Collaborator

    The routes are tried in the order they are passed to the constructor. If you specify them with files, then the order of the files in the api() call determines it. If you specify it programmatically then by default new routes are added to the end of the stack.

    The migration guide is def not done yet and this would be a good thing to add

  7. jrosell commented on Jun 6, 2025

    @jrosell

    Thanks. At the moment, I migrated the previous plumber code to plumber2 using headers.

    rlang::check_installed(c("yyjsonr", "plumber2", "httr2", "bench", "callr", "palmerpenguins", "ggbeeswarm", "ggplot2"))
    
    library(plumber2)
    library(palmerpenguins)
    data(package = 'palmerpenguins')
    
    get_penguins <- \(n = 100) {
      np <- nrow(penguins)
      idx <- sample(1:np, n, replace = TRUE)
      penguins[idx, ]
    }
    
    read_penguins <- \(body, query, request) {
      started_at  <- as.POSIXct(request$headers$Started_At)
      elapsed <- as.numeric(Sys.time() - started_at)  
      elapsed
    }
    
    register_serializer("yyjson", mime_type = "application/json", fun = \(...) {
      \(x) {
        yyjsonr::write_json_str(x, ...)
      }
    })
    
    register_parser("yyjson", mime_type = "application/json", fun = \(...) {
      \(raw, directives) {
        yyjsonr::read_json_raw(raw, ...)
      }
    })
    
    app <- api(port = 3000L) |>
      api_get("/serialize", get_penguins, serializers = get_serializers("json")) |>  
      api_get("/serialize-yy", get_penguins, serializers = get_serializers("yyjson")) |>
      api_post("/deserialize", read_penguins, serializers = get_serializers("text"), parsers = get_parsers("json")) |>
      api_post("/deserialize-yy", read_penguins, serializers = get_serializers("text"), parsers = get_parsers("yyjson")) |>
      api_run()
    
    
    get_pengos <- \(n) {
      start <- Sys.time()
      httr2::request("http://127.0.0.1:3000/serialize?") |>
        httr2::req_url_query(n = n) |>
        httr2::req_perform()
      Sys.time() - start
    }
    
    get_pengos_yy <- \(n) {
      start <- Sys.time()
      httr2::request("http://127.0.0.1:3000/serialize-yy?") |>
        httr2::req_url_query(n = n) |>
        httr2::req_perform()
      Sys.time() - start
    }
    
    benches <- bench::press(
      n = c(1e1, 1e2, 1e3, 1e4, 1e5, 1e6),
      niter = 25,
      {
        bench::mark(
          jsonlite = get_pengos(n),
          yyjsonr = get_pengos_yy(n),
          iterations = niter,
          check = FALSE
        )
      }
    )
    
    plot(benches) + ggplot2::labs(title = "plumber2 serialize json")
    
    
    
    library(palmerpenguins)
    data(package = 'palmerpenguins')
    
    deserialize <- \(n) {
      np <- nrow(penguins)
      idx <- sample(1:np, n, replace = TRUE)  
      httr2::request("http://127.0.0.1:3000/deserialize") |>
        httr2::req_headers("Started_At" = as.character(Sys.time())) |>
        httr2::req_body_json(penguins[idx, ]) |>
        httr2::req_perform()  
    }
    
    deserialize_yy <- \(n) {
      np <- nrow(penguins)
      idx <- sample(1:np, n, replace = TRUE)  
      httr2::request("http://127.0.0.1:3000/deserialize-yy") |>
        httr2::req_headers("Started_At" = as.character(Sys.time())) |>
        httr2::req_body_json(penguins[idx, ]) |>
        httr2::req_perform()  
    }
    
    benches_de <- bench::press(
      n = c(1e1, 1e2, 1e3, 1e4, 1e5),
      niter = 25,
      {
        bench::mark(
          jsonlite = deserialize(n),
          yyjsonr = deserialize_yy(n),
          iterations = niter,
          check = FALSE
        )
      }
    )
    
    plot(benches_de) + ggplot2::labs(title = "plumber2 deserialize json")
    

    Image
    Image

  8. thomasp85 commented on Jun 20, 2025

    @thomasp85
    Collaborator

    recent testing suggests that yyjsonr can result in segfaults on certain malformed input, so I'll hold off on this a while longer

  9. dotschkis commented on Apr 25, 2026

    @dotschkis

    recent testing suggests that yyjsonr can result in segfaults on certain malformed input, so I'll hold off on this a while longer

    The issues described in yyjsonr should have been addressed in the latest CRAN release: coolbutuseless/yyjsonr#63

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions