Skip to content

Benchmarks

The benchmarks time decoding, which a service does on every request. They compare ryjwt with:

ryjwt is timed decoding into a msgspec Struct, a pydantic BaseModel, and a dict, built by msgspec (when it's installed) and by jiter (when it isn't). The results:

  • The races: the two cases below, each library timed for 3 rounds of 10 seconds.
  • Full matrix: every algorithm and key size, four payload sizes, and four key sources (HMAC secret, PEM public key, JWKS document, JWKS URL).
  • HS256 by token and key size: tokens from 231 bytes to 20 KB, secrets from 32 bytes to 4 KB.

The races

Each bar is one library decoding the same token 100,000 times, filling in at its mean speed over 3 rounds of 10 seconds. The races page has each library's time and its range over the three rounds.

A race to decode 100,000 HS256 tokens: ryjwt finishes in about 0.14 seconds, jsonwebtoken (Rust) in about 0.3 to 0.4, fast-jwt (Bun) in about 0.45, and jose, joserfc and PyJWT in about 1.3 to 3.9 seconds

With HS256, ryjwt decodes a typical token over 27 times faster than PyJWT 2.15 into a Struct (over 26 times into a dict, 22 times with jiter). Against jsonwebtoken (Rust), it's about 2.2 times faster struct to struct, and 2.1 to 2.5 times faster dict to Value. It's about 3.2 times faster than fast-jwt (Bun). Even into a pydantic model it's a little faster than jsonwebtoken's struct, and about 14 times faster than PyJWT.

Why it's faster than jsonwebtoken (Rust)

Both use the same token, checks and crypto library (aws-lc), so the gap is the work per token. For each token, jsonwebtoken 11 parses the header twice, sets up the HMAC key again, and deserialises the claims twice: for the result, and to check them. ryjwt sets up the HMAC key once, when the key is created, skips headers it has already verified, and checks the claims while building the result.

RS256

A race to decode 100,000 RS256 tokens with a 3072-bit RSA key: ryjwt finishes first in about 2.9 seconds, fast-jwt (Bun) and jsonwebtoken (Rust) next in 3.4 to 3.6, jose in 4.2, joserfc in 5.3, and PyJWT in 7.9

Most identity providers sign with RS256 by default. Most of the time goes on checking the signature, which every library hands to native crypto, so the gaps are smaller. ryjwt still finishes first, about 2.7 times faster than PyJWT, and ahead of fast-jwt and jsonwebtoken by about 14% and 18%. It finishes first on x86_64 too, about 15% ahead of jsonwebtoken and fast-jwt (cross-check).

With ES256, ryjwt is about 2.1 times faster than PyJWT, and a little ahead of jsonwebtoken and fast-jwt, by about 5% and 9% (full matrix).

How they're measured

  • Each decode checks the signature, exp and aud, as a real service would.
  • ryjwt is built from the code being benchmarked as its released wheels are, with profile-guided optimisation (trained on the CodSpeed benchmarks, benchmarks/).
  • Before timing, each library's result is checked against the token's claims, and each is shown to reject an expired token and one for another audience.
  • The published numbers come from AWS m9g.2xlarge instances, virtual machines with 8 Graviton5 (Arm) cores. GitHub's x86_64 runners, which get different CPUs from run to run, are used for a cross-check. Either way it's a virtual machine, so expect a few percent of variation between runs.
  • Each library runs in its own Docker container, with one CPU (pinned to one core) and 500 MB of memory. For the races and the HS256 by-size tables, the containers run one after another. The full matrix runs several at once, each on a core of its own (its page says how); where it times the same token as the races, its times are within 7% of theirs.
  • jose and fast-jwt run on Bun, whose crypto is BoringSSL. On Node (OpenSSL), their numbers could differ.
  • JWKS URL cases fetch the keys over HTTPS from another container, and are timed once the keys are cached.
  • The races give each library 1 second of untimed decodes, then time 3 rounds of 10 seconds each, so every library is timed for as long, however fast it is, and Bun's JIT has warmed up. The tables start each case with 1,000 untimed decodes, then time 10,000, once. Times are microseconds per decode (lower is better), the mean over every timed decode, with the speed-up over PyJWT.

When reading them, note:

  • The same token, every time. Each case decodes one token repeatedly, so ryjwt's header cache always hits, as it does for tokens from one issuer, which share a header. The signature and claims are still checked on every decode.
  • ryjwt → dict is timed both ways. With msgspec installed, ryjwt builds dicts with it; without (uv add ryjwt), with jiter, which is slower. The jiter lane hides msgspec, and checks it really is jiter that's parsing.
  • The speed-ups are against PyJWT 2.15. Much of PyJWT's time goes on its own Python code, such as checking each base64 character, so another version would give different speed-ups.

Each results page says when it was made, and with which versions.

Apple Silicon

In Docker on an Apple Silicon Mac, aws-lc (the crypto library under ryjwt and jsonwebtoken) runs RSA, Ed25519, P-384 and P-521 checks about 1.6 to 1.8 times slower than natively, as it doesn't recognise the CPU. HS256 and ES256 aren't affected. Neither is Linux on x86_64, or on Arm servers such as AWS Graviton (where the published numbers come from) and GitHub's arm64 runner. Results made on a Mac carry a note saying so.

Running them

The benchmarks are in the repository's bench/ directory. You need Docker, uv and Task:

task bench-docker  # HS256: bench/results-docker.md
task bench-matrix  # the full matrix: bench/results-matrix.md
task bench-race    # the races: bench/results-race.md, then redraws them
task race-svg      # redraws the races from bench-race's results

These pages show those files as is, so rerunning the benchmarks updates the docs.

To run them on Linux, for any commit or tag, run the Benchmarks workflow from the repository's Actions tab, choosing the ref, benchmarks (race for just the races) and runner (x86_64 or arm64). It uploads the results, with a note of the machine, as an artifact; task bench-download -- <run id> puts them in place. For the cross-check, run all on x86_64 and fetch it with task bench-download CROSS_CHECK=x86_64 -- <run id>. GitHub's Linux runners don't have the Apple Silicon slowdown.

To update the published numbers, run task bench-aws, with the AWS CLI and an AWS profile named ryjwt-benchmarks. It runs the races, the HS256 tables and the two halves of the matrix each on an AWS m9g.2xlarge spot instance of its own, all at once, spread over the region's zones, for about 25 minutes. When AWS reclaims an instance, only that piece runs again, on a new one. The results, pages and redrawn races land in place as each piece finishes, and every instance is terminated at the end, or on Ctrl-C. It benchmarks main as it is on GitHub; -- --ref <branch, tag or SHA> picks another.