$ show rust-sailfish/sailfish
Sailfish is a compile-time template engine for Rust, designed for high-performance server-side rendering. Unlike runtime template engines that parse templates on every request, Sailfish uses procedural macros to parse `.stpl` files and generate optimized Rust code at compile time. This architecture ensures type safety, eliminates runtime parsing overhead, and allows for aggressive compiler optimizations. The engine integrates seamlessly with Rust's ecosystem, supporting features like embedded Rust code, filters, and includes within templates. The architecture is split into three main crates: `sailfish-compiler` handles the parsing and translation of template syntax into Rust AST, `sailfish-macros` provides the derive macros that trigger compilation, and `sailfish` contains the runtime logic for rendering and buffer management. The project emphasizes performance through custom memory allocation strategies and SIMD-optimized HTML escaping routines. It also includes comprehensive editor support via Tree-sitter grammars and VS Code/Vim syntax extensions. While the core engine is robust and well-architected, there are significant maintenance inconsistencies. The `Cargo.toml` specifies `edition = "2024"`, which is not a stable Rust edition, indicating experimental or forward-looking configuration. Additionally, the `CHANGELOG.md` lags significantly behind the actual version in `Cargo.toml` (v0.4.0 vs 0.11.2), suggesting documentation is not kept in sync with releases. Despite these issues, the codebase demonstrates high craftsmanship in its performance-critical components.
The LLM identified 3 files worth highlighting for reuse:
Implements AVX2 SIMD instructions for HTML entity escaping. This component demonstrates non-obvious skill by bypassing standard library functions to achieve higher throughput through vectorized operations. It is safely reusable as a standalone performance primitive for any Rust project requiring high-speed string sanitization.
Contains the core compilation pipeline that transforms template syntax into Rust code. It handles parsing, semantic analysis, and code generation in a modular fashion. This module is a high-quality example of a domain-specific language compiler and could be adapted for other template or DSL systems.
Provides a custom buffer implementation designed to minimize heap allocations during template rendering. It uses a pre-allocated strategy with dynamic resizing only when necessary. This pattern is reusable for any high-performance I/O or string-building task in Rust where allocation overhead is a bottleneck.