All articles
Comparisons·December 15, 2025·5 min read

Python vs Rust for Crypto HFT Bots: Where Python Breaks Down

Python dominates quant research but its GIL and garbage collector create hard ceilings for sub-millisecond execution. This article pins down the exact throughput thresholds where you must switch to Rust.

Most teams ship their first bot in Python. That is the right call — the research loop is fast, numpy and pandas are genuinely good, and the ecosystem for backtesting is hard to beat. The problem surfaces later, when you move into live execution and start reading your latency percentiles. Python is not slow in the abstract. It is slow in the specific ways that kill you in production HFT.

What "fast enough" actually means in crypto

On Hyperliquid, the matching engine processes orders in roughly 20–50 ms end-to-end at the protocol layer. That sounds forgiving until you account for your own stack: WebSocket parse, signal computation, order construction, and send. Your slice of that budget is measured in single-digit milliseconds if you want to trade competitively against other bots. On Solana, the situation is harsher — slot times are 400 ms but the orderflow competition on programs like Phoenix or OpenBook means your effective window to act on a signal can be under 5 ms before the price moves.

The rule of thumb: if your median round-trip (signal-in to order-out) exceeds 1–2 ms in your own process, Python is costing you edge. At 5 ms you are almost certainly leaving money on the table against a Rust competitor.

The GIL is not your biggest problem — GC pauses are

Developers fixate on Python's Global Interpreter Lock, but in a single-threaded hot loop the GIL is mostly irrelevant. The real killer is CPython's cyclic garbage collector. When you create and discard thousands of dict and list objects per second — which is exactly what happens when you parse a high-frequency WebSocket feed — the GC periodically stops the world to collect cycles. These pauses are not predictable. In a load test against a Binance L2 feed at 10,000 messages per second, a typical CPython process shows GC pauses between 2 ms and 15 ms occurring every few seconds. At the wrong moment, that pause is your entire trading window.

You can partially mitigate this with gc.disable() and manual gc.collect() calls in controlled windows, but then you are fighting the runtime instead of building strategy. PyPy helps with GC but breaks most of the C-extension ecosystem you depend on.

Where Python genuinely holds up

This is not an argument to rewrite everything in Rust. Python earns its place in the stack:

  • Strategy research and signal discovery. Vectorized backtests over millions of candles run in seconds with pandas and polars. Rust offers no productivity advantage here.
  • Risk management and position tracking. These run on human-readable timescales. A 10 ms latency on a position check does not matter.
  • Infrastructure glue. Config loading, Telegram alerts, monitoring dashboards — Python is fine and fast to write.
  • Parameter optimization loops. Optuna, scipy, hyperparameter searches — the compute is numpy/C under the hood anyway.

The pattern we use internally is Python for everything that runs slower than 100 ms, Rust for everything on the critical execution path.

The Rust execution path: what you actually gain

A Rust hot loop parsing a binary WebSocket frame, running a simple signal calculation, and writing an order to a TCP socket can complete in under 100 microseconds on commodity hardware. More importantly, the latency distribution is tight — p99 is often within 2–3x of p50, whereas Python p99 can be 20–50x p50 due to GC and interpreter overhead.

Concrete wins in the bots we build for Solana and Hyperliquid execution:

  • Zero-copy deserialization via serde and bytes crate — parse a Hyperliquid order book update without allocating heap memory.
  • Tokio async runtime gives you concurrent WebSocket connections and order management with deterministic scheduling and no GIL contention.
  • Predictable memory layout. Struct fields are packed in cache-friendly order. A Python dict lookup involves pointer chasing; a Rust struct field is an offset computation.
  • No runtime surprises. Rust does not have a garbage collector. Pause time is zero. Memory is freed when objects go out of scope, deterministically.

The rewrite cost is real — Rust has a steep learning curve, and a bug in unsafe code can be subtle. But for a market-making bot running 24/7 on a venue like Hyperliquid where you are quoting hundreds of times per minute, the performance headroom pays back the development investment within weeks of live trading.

Latency thresholds: a practical decision matrix

Median round-trip Recommendation
> 50 ms Python is fine; optimize your strategy first
10–50 ms Python with profiling; fix allocations, use msgspec/orjson
2–10 ms Python ceiling is near; prototype in Rust, A/B test
< 2 ms Rust required; Python cannot reliably hit this at p99

One common intermediate step is keeping Python for signal generation but calling into a Rust extension (via PyO3) for the order submission path. This can halve your tail latency without a full rewrite.

The migration path teams actually follow

You do not rewrite a working bot from scratch. The approach that works: identify your p95 and p99 latency from production logs, trace the slow frames to specific Python functions, and extract those functions into a Rust library called via FFI or a local Unix socket. The first extraction is always the WebSocket parser and order builder. The second is usually the order book state machine. After those two, most teams find they have hit their latency targets and stop there.

The Python layer stays — it handles configuration, logging, risk limits, and any logic that runs on a 100 ms or slower cadence. The Rust layer owns the microsecond-sensitive execution path. This hybrid architecture is what most production crypto HFT shops actually run.


If you are hitting latency ceilings in your current bot stack or building execution infrastructure from scratch on Solana or Hyperliquid, talk to us — we have shipped this architecture in production and can cut your time-to-live significantly.

Need a bot like this built?

We design, build and run trading bots on Solana, Hyperliquid and Polymarket.

Start a project
#HFT#Python#Rust#trading bots#performance#Solana#Hyperliquid#low latency#crypto