Belderbos

How Rust rides inside Python

Cover art for How Rust rides inside Python

TL;DR: When you port Rust into Python, profile the boundary. Building Python objects on the way out can cost more than the algorithm itself. A tiny JSON parser in Rust shows where PyO3 ports actually get slow, and it is not the parsing. Every Pydantic v2 validation call hands the work to a Rust extension.

Bob Belderbos

From · · · 3m

TL;DR: How Rust rides inside Python

A tiny JSON parser in Rust shows where PyO3 ports actually get slow, and it is not the parsing.

When you port Rust into Python, profile the boundary. Building Python objects on the way out can cost more than the algorithm itself. A tiny JSON parser in Rust shows where PyO3 ports actually get slow, and it is not the parsing. Every Pydantic v2 validation call hands the work to a Rust extension.

  • You already run Rust
  • A parser small enough to read
  • Four steps to import
  • Macros are the wiring

Read the story version — the same reporting as a swipeable deck of 12 cards.

Read the original on Belderbos

How we make summaries

React

Sign in to react and comment.

Comments (0)

Life is short. Keep it sweet. Respect others' opinions and be kind!

    Recommended next

    More decks on rust and related topics.