pain001-fast: Native Rust High-Throughput Core

Sub-25ns zero-allocation validation and 50,000+ tx/s multi-core batch processing for high-frequency financial gateways.

High-Throughput Native Acceleration for ISO 20022#

pain001-fast is an optional, high-throughput native acceleration core written in Rust with PyO3 bindings. Designed for corporate treasury backbones, high-frequency clearing hubs, and payment service providers, it offloads CPU-intensive validation loops from the Python Global Interpreter Lock (GIL) to parallel multi-core hardware.

Status: experimental. Version 0.0.91 joins the pain001 suite in lockstep. Source and native wheels are distributed through GitHub Releases; the package is not published on PyPI or crates.io.

When the pain001_fast module is importable, pain001 core uses it for IBAN, BIC, and character set validation without any configuration or API changes; when it is not, pain001 uses its own Python routines.


Performance Characteristics#

Micro-benchmarked by the project on Apple Silicon (M-series), release build; these figures have not been reproduced independently:

Benchmark Scenario Standard Pure Python pain001-fast (Rust) Speedup Factor
IBAN Checksum (Mod-97) 1,850 ns / op 22 ns / op ~84× faster
BIC Structural Check 1,200 ns / op 14 ns / op ~85× faster
SWIFT-X Diacritic Sanitization 2,100 ns / op 115 ns / op ~18× faster
Batch Analysis (10,000 orders) 3,450 ms 165 ms > 60,000 tx/sec
Heap Memory Overhead ~12 objects / tx 0 heap allocations Zero Allocation

Core Capabilities#

1. Zero-Allocation Mod-97 Engine

Implements ISO 7064 mod-97-10 check digit verification directly in CPU registers. By streaming ASCII character byte arithmetic through an inlined modular accumulator, pain001-fast completely eliminates the big integer string heap allocations that constrain standard interpreter runtimes.

2. Regex-Free Structural BIC Parsing

Validates 8 and 11 character ISO 9362 Business Identifier Codes using inlined byte checks and branchless lookup tables against the official ISO 3166-1 alpha-2 country registry.

3. NFKD Character Set Sanitizer

Fast Unicode normalization decomposes accented characters (such as é to e, ü to u) and replaces unpermitted characters with compliant ASCII delimiters in sub-microsecond time.

4. Parallel Multi-Core Batch Analyzer

Leverages Rayon work-stealing thread pools to validate thousands of transaction records across all available CPU cores simultaneously:

  • Calculates per-currency control sums and counts.
  • Builds SHA-256 / composite collision fingerprints to detect duplicate payments in memory.
  • Returns comprehensive structured diagnostic reports with sub-50ms p99 latency.

Python API Quick Start#

from pain001_fast import validate_iban, validate_bic, validate_payment_batch

# Sub-25ns IBAN validation
assert validate_iban("DE89370400440532013000") is True

# Structural BIC verification
assert validate_bic("DEUTDEFF500") is True

# High-throughput batch validation across CPU cores
orders = [
    {
        "creditor_iban": "DE89370400440532013000",
        "creditor_bic": "DEUTDEFF",
        "amount": "1250.00",
        "currency": "EUR",
        "execution_date": "2026-10-01",
    }
]

report = validate_payment_batch(orders)
assert report["valid"] is True
assert report["transaction_count"] == 1
assert report["control_sums"]["EUR"] == 1250.00

Architectural Guarantee & Fallback#

pain001-fast exposes standalone validation helpers. Import them explicitly; installing the extension does not activate it in the core library. Use the core library for payment XML generation and validation, including environments such as Pyodide where this native extension is unavailable.