Skip to content

Benchmarks

This page summarizes how fast environments run with ruxla. The full methodology, per-environment results, and analysis are in the paper.

Setup

  • Machine. AMD Ryzen 9 9950X (16 cores) and NVIDIA RTX 5090 under Linux; JAX 0.12; Rust with -C target-cpu=native.
  • Environments. 71 environments of gymnax, Pgx, and Jumanji, imported from their original JAX implementations (Importing JAX environments), plus a few large environments.
  • Same trajectories, same work. Every implementation starts from the same keys, takes the same actions (legal ones where the environment has a mask), and runs the same number of steps from the reset. Integer and boolean state agree exactly with JAX, floats within a small tolerance.
  • Configurations. On the CPU: 1 environment on 1 thread, 64 on 1, 1,024 on 16, and 4,096 on 16. JAX runs with vmap and scan on one XLA thread, or one device per thread with shard_map.
  • Repetitions. One warm-up run and 10 timed runs; results are geometric means over the 71 environments.

Imported code against JAX on the CPU

Speedup of the imported environments, compiled ahead of time by ruxla, over the same environments run by JAX on the CPU (geometric mean over 71 environments; higher is faster):

1 env, 1 thread 64 envs, 1 thread 1,024 envs, 16 threads 4,096 envs, 16 threads
11.2× 5.1× 5.9× 6.5×
  • Robustness. Against a stronger JAX baseline (a lazy reset that builds a new episode only when one ends), and with the generated code also reducing every output to a checksum so that both sides produce the same output work, the imported code remains 3.1× faster with 1 environment on 1 thread and 2.1× with 4,096 environments on 16 threads.
  • Close to handwritten Rust. The generated code takes 1.3 to 1.4 times the time of plain Rust written by hand with the same algorithm.
  • ruxla environments inside JAX run at the original's speed: a port written with ruxla, exported and stepped inside a JAX program, runs at 1.01 to 1.08 times the speed of the original JAX environment on CPU and GPU (ruxla environments in JAX).

CPU or GPU

With one environment, native code on one CPU core is faster than JAX on an RTX 5090 for 69 of the 71 environments, by a median factor of 470. With larger batches the GPU catches up: it exceeds the best throughput of 16 CPU cores on 58 of the 71 environments, from a median batch of 16,384 environments. See Choosing CPU or GPU for practical guidance.

Large environments

Speedup of the imported code over JAX on the CPU, with 1 environment on 1 core and with 16 cores at the batch where the imported code is fastest. These environments were exported with custom wrappers that are not shipped in this repository.

Environment 1 core 16 cores
Craftax (symbolic) 228× 578×
Craftax Classic 60× 203×
Waymax (planning agent) 6.4× 2.3×
Brax Ant (MJX) 1.5× 5.5×
Brax Humanoid (MJX) 1.3× 3.2×

Rule-based worlds gain the most, because the generated code builds a new world only when an episode ends, while batched JAX builds one on every step. Rigid-body physics in large batches remains a GPU workload.

PyTorch PPO

PPO with the structure of CleanRL in PyTorch, with the agent compiled as LeanRL does (torch.compile with CUDA graphs, a compiled loss, and a fused Adam) on an RTX 5090, and the same exported environment stepped five ways: by ruxla's VecEnv on 16 threads, and by jit and vmap of JAX on the CPU or the GPU, the latter two also with the optimistic reset (shared reset states, as PureJaxRL's Craftax PPO does). The table gives the training throughput after warm-up of ruxla relative to the best of the four JAX backends (ratios of mean throughput over 3 seeds; higher is faster). See Using ruxla from PyTorch for the setup and the example.

Environment 8 envs 64 envs 1,024 envs
Breakout-MinAtar 1.44× 1.38× 1.02×
Connect Four 1.42× 1.45× 1.36×
Craftax Classic 3.19× 4.42× 1.24×
Craftax 5.76× 3.27× 0.57×
Go 9×9 1.64× 1.74× 0.65×
Tic-tac-toe 1.47× 1.40× 1.51×
Backgammon 1.66× 1.54× 1.12×
Gardner chess 0.62× 0.44× 0.14×
Kuhn poker 1.41× 1.42× 1.53×
  • Small batches. At 8 and 64 environments, imported environments raise throughput by 1.4 to 5.8 times on eight of the nine tasks, and by 1.5 times or more at both sizes on four (Craftax Classic, Craftax, Go 9×9, and backgammon). They lose on Gardner chess, whose imported step computes legal moves densely.
  • Large batches. At 1,024 environments, the gain stays between 1.0 and 1.5 times on six tasks, and ruxla loses on Go 9×9, Craftax, and Gardner chess, where stepping on the host and copying the observations to the GPU take longer than stepping on the GPU.
  • Time to target. With targets declared before the runs and 64 environments, ruxla reaches a return of 6 on Breakout-MinAtar in 0.74 times the time of the fastest JAX backend (paired ratio over 5 seeds, 95% interval 0.70 to 0.78; 4.9 s against 6.6 s for JAX on the CPU) and a return of 0.8 on Go 9×9 in 0.58 times (0.57 to 0.59; 1.0 s against 1.8 s for JAX on the GPU), with returns identical to JAX's at every log entry. With the uncompiled agent, it reaches a return of 4 on Craftax 3.0 times sooner than JAX on the GPU (13.7 s against 41.6 s, and 48.0 s with the optimistic reset; times after warm-up).
  • An agent written in JAX trains faster in a loop fused into one jax.jit on the GPU than any of these host loops (on Breakout-MinAtar, 47 ms against 87 ms per update).

The gain holds on two server nodes with one GPU and 16 physical cores each: every ratio at 8 and 64 environments falls on the same side of 1 as on the RTX 5090. The H200 node has 32 logical CPUs on 16 cores of an Intel Xeon Platinum 8480+, the B300 node 16 cores of an Intel Xeon 6767P.

Environment RTX 5090, 8 RTX 5090, 64 H200, 8 H200, 64 B300, 8 B300, 64
Breakout-MinAtar 1.44× 1.38× 1.65× 1.46× 1.70× 1.63×
Connect Four 1.42× 1.45× 1.67× 1.86× 1.68× 1.69×
Craftax Classic 3.19× 4.42× 3.23× 3.45× 3.84× 4.66×
Craftax 5.76× 3.27× 4.85× 2.04× 6.39× 2.99×
Go 9×9 1.64× 1.74× 2.03× 1.85× 2.07× 1.99×
Tic-tac-toe 1.47× 1.40× 1.57× 1.65× 1.67× 1.69×
Backgammon 1.66× 1.54× 1.68× 1.63× 1.89× 2.00×
Gardner chess 0.62× 0.44× 0.65× 0.58× 0.68× 0.62×
Kuhn poker 1.41× 1.42× 1.62× 1.72× 1.60× 1.67×
Geometric mean 1.72× 1.60× 1.84× 1.66× 1.99× 1.86×

ruxla reaches 1.5 times at both batch sizes on seven of the nine tasks on the H200 and on eight on the B300, against four on the RTX 5090.

Compilation time

Ahead-of-time compilation happens once per build and is cached by Cargo: under a second for small environments (gymnax CartPole: 0.4 s of rustc), about 12 s for Craftax (code generation and rustc), and up to about 100 s for the largest MuJoCo Playground task.