Rust-accelerated backend for markdown-it-py with 50-200x performance improvements
Project description
markdown-it-accel
Rust-accelerated backend for markdown-it-py
markdown-it-accel provides a drop-in Rust-accelerated backend for markdown-it-py, offering significant performance improvements for markdown rendering while maintaining full compatibility with the original Python implementation.
Features
- Blazing fast performance: Up to 80x speedup on typical documents, 200x+ on large documents
- Drop-in acceleration: Simply import and apply to existing markdown-it-py instances
- Automatic fallback: Gracefully falls back to Python implementation when needed
- Full CommonMark support: Powered by pulldown-cmark
- Cross-platform: Pre-built wheels for Linux, macOS, and Windows
- Python 3.8+ support: Compatible with modern Python versions
Installation
Install from PyPI:
pip install markdown-it-accel
For development or building from source:
# Clone the repository
git clone https://github.com/ChungNYCU/markdown-it-accel.git
cd markdown-it-accel
# Install Rust (if not already installed)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Install in development mode
pip install maturin
maturin develop
Quick Start
from markdown_it import MarkdownIt
from markdown_it_accel import use_rust_core
# Create a markdown-it-py instance
md = MarkdownIt()
# Apply Rust acceleration
use_rust_core(md)
# Use as normal - now with Rust speed!
html = md.render("# Hello, *World*!")
print(html) # <h1>Hello, <em>World</em>!</h1>
Performance
Based on comprehensive benchmarking, markdown-it-accel delivers significant performance improvements:
Performance Results
Overall Speedup: 67x faster on average
| Document Type | Size | Python Time | Rust Time | Speedup |
|---|---|---|---|---|
| BIG.md | 8.0KB | 5.69ms | 71.3μs | 79.88x |
| CODE_HEAVY.md | 8.7KB | 1.28ms | 27.6μs | 46.56x |
| HUGE.md | 434KB | 230.80ms | 3.57ms | 64.68x |
| TABLE_HEAVY.md | 2.1KB | 3.55ms | 46.5μs | 76.36x |
Library Comparison
Compared to other Python markdown libraries:
| Library | Time | Throughput | Relative Performance |
|---|---|---|---|
| markdown-it-accel (Rust) | 80.1μs | 100.5M chars/sec | Fastest |
| markdown-it-py (Python) | 5.72ms | 1.4M chars/sec | 71x slower |
| python-markdown | 25.00ms | 322K chars/sec | 312x slower |
Scaling Performance
Performance scales excellently with document size:
- 1x size: 38x speedup
- 10x size: 132x speedup
- 50x size: 201x speedup
Run benchmarks on your system:
# Comprehensive benchmark suite
python bench/scripts/benchmark.py
# Library comparison
python bench/scripts/compare_libraries.py
Configuration
Environment Variables
MARKDOWN_IT_ACCEL=0: Disable Rust acceleration (fallback to Python)MARKDOWN_IT_ACCEL=1: Enable Rust acceleration (default)
# Disable Rust acceleration
MARKDOWN_IT_ACCEL=0 python your_script.py
# Enable Rust acceleration (default behavior)
MARKDOWN_IT_ACCEL=1 python your_script.py
Checking Availability
from markdown_it_accel import is_available, get_version
print(f"Rust acceleration available: {is_available()}")
print(get_version())
Compatibility
Supported Features
- Headers (
#,##, etc.) - Emphasis (
*italic*,**bold**) - Links (
[text](url)) - Images (
) - Lists (ordered and unordered)
- Code blocks (fenced and indented)
- Blockquotes (
>) - Tables (GFM extension)
- Strikethrough (
~~text~~) - Line breaks and paragraphs
Fallback Behavior
The library automatically falls back to the Python implementation when:
- Rust extension is not available (installation without binary wheels)
- Unsupported syntax is detected
- Rust renderer encounters an error
This ensures your code continues to work regardless of the environment.
Limitations
Currently, some advanced markdown-it-py features may trigger fallback:
- Custom plugins and renderers
- Complex HTML blocks
- Math expressions (
$$...$$) - Mermaid diagrams
Development
Prerequisites
- Python 3.8+
- Rust 1.70+
- maturin
Setup
# Clone and enter directory
git clone https://github.com/ChungNYCU/markdown-it-accel.git
cd markdown-it-accel
# Create virtual environment
python -m venv .venv
source .venv/bin/activate # or .venv\Scripts\activate on Windows
# Install dependencies
pip install -e .[dev]
Building
# Development build
maturin develop
# Release build
maturin develop --release
# Build wheels
maturin build --release
Testing
# Run tests
pytest tests/
# Run tests with coverage
pytest tests/ --cov=markdown_it_accel
# Run benchmarks
python bench/bench_render.py
Code Quality
# Format Python code
black .
# Lint Python code
ruff check .
# Format Rust code
cargo fmt
# Lint Rust code
cargo clippy
Architecture
The library consists of three main components:
- Rust Core (
src/lib.rs): PyO3 module using pulldown-cmark for fast HTML generation - Python Shim (
markdown_it_accel/_shim.py): Monkey-patches markdown-it-py instances - Fallback Logic: Automatic detection and graceful degradation
How It Works
# Before acceleration
md = MarkdownIt()
html = md.render(text) # Pure Python
# After acceleration
use_rust_core(md)
html = md.render(text) # Rust + Python fallback
The use_rust_core() function replaces the render method with a wrapper that:
- Checks if content is supported by Rust implementation
- Attempts fast Rust rendering via
pulldown-cmark - Falls back to original Python implementation on any issue
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development Workflow
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add tests for new functionality
- Ensure tests pass (
pytest) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- markdown-it-py - The Python markdown parser this library accelerates
- pulldown-cmark - The fast Rust markdown parser powering the acceleration
- PyO3 - Rust bindings for Python
- maturin - Build system for Rust-based Python extensions
Changelog
0.1.0 (2025-09-03)
- Initial release
- Basic CommonMark support with Rust acceleration
- Automatic fallback mechanism
- Cross-platform binary wheels
- Comprehensive test suite and benchmarks
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file markdown_it_accel-0.1.0.tar.gz.
File metadata
- Download URL: markdown_it_accel-0.1.0.tar.gz
- Upload date:
- Size: 74.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a04e77109b87ea764767e3e31312827950e36ce49dda9292a32efb7a33a808b
|
|
| MD5 |
eb03ebc6909f99ed24dc0a8725df2070
|
|
| BLAKE2b-256 |
9f62a047e4799f54494f73823d6a7a934259fbb6d322f677036771d9c1b44193
|
File details
Details for the file markdown_it_accel-0.1.0-cp38-abi3-win_amd64.whl.
File metadata
- Download URL: markdown_it_accel-0.1.0-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 200.0 kB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb9ad2203b93711b717f840456603ec426b35ca766445a6ea638f887e044be6b
|
|
| MD5 |
2f26ba8d077b2377a52223e4e01084e0
|
|
| BLAKE2b-256 |
4710a7bc644a03c368d684b7565b5b4235b38d180fd1a4d318491cb1476609a5
|
File details
Details for the file markdown_it_accel-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: markdown_it_accel-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 344.5 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f061c9d612d6f046e4baec8ef3c213b8c1ea623fb693e7850eabe215a5732c5a
|
|
| MD5 |
1f664acf460f6762df757af8192d9553
|
|
| BLAKE2b-256 |
a6d0422921886dd827fa862bd22f2b4abae9136e08f8f5497e86ebf233713708
|
Provenance
The following attestation bundles were made for markdown_it_accel-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
ci.yml on ChungNYCU/markdown-it-accel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
markdown_it_accel-0.1.0-cp38-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl -
Subject digest:
f061c9d612d6f046e4baec8ef3c213b8c1ea623fb693e7850eabe215a5732c5a - Sigstore transparency entry: 464180398
- Sigstore integration time:
-
Permalink:
ChungNYCU/markdown-it-accel@4cf07f2eb77c5c4b4ccfb564a4924a2520c25236 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ChungNYCU
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@4cf07f2eb77c5c4b4ccfb564a4924a2520c25236 -
Trigger Event:
release
-
Statement type:
File details
Details for the file markdown_it_accel-0.1.0-cp38-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: markdown_it_accel-0.1.0-cp38-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 286.3 kB
- Tags: CPython 3.8+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dae0de2ed035660d21342a410df36549a4df01abdf80428a3be73b51bcffa499
|
|
| MD5 |
625b1c8bbcbe1c10c4fbf2d70f75ea07
|
|
| BLAKE2b-256 |
bd828eebed8fc2331696197e738f76021cf1980ce396ab88cbe7898ed32aa987
|
Provenance
The following attestation bundles were made for markdown_it_accel-0.1.0-cp38-abi3-macosx_11_0_arm64.whl:
Publisher:
ci.yml on ChungNYCU/markdown-it-accel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
markdown_it_accel-0.1.0-cp38-abi3-macosx_11_0_arm64.whl -
Subject digest:
dae0de2ed035660d21342a410df36549a4df01abdf80428a3be73b51bcffa499 - Sigstore transparency entry: 464180140
- Sigstore integration time:
-
Permalink:
ChungNYCU/markdown-it-accel@4cf07f2eb77c5c4b4ccfb564a4924a2520c25236 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ChungNYCU
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@4cf07f2eb77c5c4b4ccfb564a4924a2520c25236 -
Trigger Event:
release
-
Statement type:
File details
Details for the file markdown_it_accel-0.1.0-cp38-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: markdown_it_accel-0.1.0-cp38-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 308.1 kB
- Tags: CPython 3.8+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dfb17ca29e1694c29bba305cb16bb2e82441e1d69cd5ef3a11b539676fe4b0ba
|
|
| MD5 |
857d86a2fc5e8c189474e7aa77ee0407
|
|
| BLAKE2b-256 |
2a85058a0c40c82337407d9f4cd6963f8c81b4351838825063898f40d83262a3
|
Provenance
The following attestation bundles were made for markdown_it_accel-0.1.0-cp38-abi3-macosx_10_12_x86_64.whl:
Publisher:
ci.yml on ChungNYCU/markdown-it-accel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
markdown_it_accel-0.1.0-cp38-abi3-macosx_10_12_x86_64.whl -
Subject digest:
dfb17ca29e1694c29bba305cb16bb2e82441e1d69cd5ef3a11b539676fe4b0ba - Sigstore transparency entry: 464180333
- Sigstore integration time:
-
Permalink:
ChungNYCU/markdown-it-accel@4cf07f2eb77c5c4b4ccfb564a4924a2520c25236 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ChungNYCU
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@4cf07f2eb77c5c4b4ccfb564a4924a2520c25236 -
Trigger Event:
release
-
Statement type: