>_ DevTrendsen

Language

Home

Languages

Sections

Frontend Backend Mobile DevOps AI / ML GameDev Blockchain Embedded Security
Rust

How to Speed Up MDX Build with Rust and Sätteri

Sätteri

If you've ever built large documentation or a blog with Astro, Next.js, or Vite, you've probably run into build speed issues. It feels like you just added a couple dozen files with code and graphics, and suddenly your project takes forty seconds to build instead of five.

The culprit is almost always the same: the traditional unified, remark, and rehype chain. These are excellent tools with thousands of ready-made plugins, but they run entirely in single-threaded JavaScript. When you need to parse a bunch of heavy .mdx files, break them into AST trees, apply transformations, and reassemble them, Node.js quickly hits its limits.

Developers from the Bruits collective decided to tackle the problem pragmatically. They created Sätteri — a Markdown/MDX parser and compiler where all the heavy lifting is done by Rust, while developers continue using familiar JavaScript.

How This Hybrid Works

The creators of Sätteri didn't rewrite everything from scratch. Instead, they took proven community solutions and tied them together using NAPI bindings.

Inside the monorepo, the project is split into two levels: low-level Rust crates and wrappers for Node.js and Vite.

At the Rust level, the following components are used:

  • satteri-pulldown-cmark — a fork of the popular pulldown-cmark parser with added MDX syntax support.
  • satteri-mdxjs-rs — a fork of the mdxjs-rs compiler, adapted for OXC — a fast-growing Rust-based JavaScript/TypeScript parser.
  • satteri-ast — MDAST and HAST node types, as well as tree operations.
  • satteri-napi-binding — a bridge layer between C++ / Rust and JavaScript.

On top sits a clean TypeScript layer. The main idea is that you don't need to learn Rust or rewrite your build scripts. You install a regular npm package and work with it like any other utility in your configuration file.

Interesting is the approach to plugin processing. Writing a compiler in Rust is a straightforward task. The real challenges begin when you need to give users the ability to modify the AST tree in JS. In Sätteri, parsing and assembling the final code happen at maximum speed inside Rust, while calls to user plugins in JavaScript happen selectively through a fast binding. The authors were honestly inspired by Lightning CSS architecture, which uses a similar principle for visitors.

Building Projects with Vite

For Vite users, the authors prepared a separate package vite-plugin-satteri. It turns connecting .md and .mdx files into a couple of configuration lines.

import { defineConfig } from 'vite';
import satteri from 'vite-plugin-satteri';

export default defineConfig({
  plugins: [
    satteri({
      // Ваши настройки и плагины
    }),
  ],
});

The bundle includes a satteri-expressive-code plugin for beautiful code block rendering. If your documentation has many syntax-highlighted examples, this combination replaces the usual heavy Rehype plugins.

Practical Benefits and Tradeoffs

Why add another tool to your project when you have libraries proven over years?

First, build speed in CI/CD and local development. When you have hundreds of pages, the difference between running operations on V8 and compiled Rust code becomes very noticeable.

Second, migration convenience. If your project has hit the performance ceiling of remark, you're usually offered either to wait patiently or rewrite everything in Go or Rust. Sätteri provides a middle ground: parsing becomes fast, while the JS plugin infrastructure remains accessible.

But there are nuances. The project is still young, with just over a thousand stars on GitHub and 23 open issues at the time of writing. This means some edge cases of MDX syntax or specific ecosystem plugins may need work. JS binding limitations also exist: if your JS plugin makes a million small calls to AST inside Rust memory, marshalling overhead could eat into some of the speed gains.

Is It Worth Trying

Sätteri is a great find for those building large content sites, documentation systems, or static site generators. If your Vite or Astro project takes seconds to load when editing MDX files, the tool definitely deserves a test.

You can try the compiler in action without installation directly in your browser via the official playground on the project website, or join the authors' Discord community to discuss features.

If you've been looking for a way to speed up your build without radically rewriting the entire pipeline in another language, try installing satteri and run benchmarks on your own files.

Related projects