How michaelciraci/monarch-butterfly works
Main Components
a. Core FFT Library:
• Represented primarily by the src/lib.rs file.
• This is where the top-level functions (fft, ifft) reside.
b. Proc-Macro / Code Generation (monarch-derive):
• Located in the crates/monarch-derive directory.
• Handles compile-time transformation to generate unrolled loops using const-evaluation.
c. Benchmark Suite:
• Found in the crates/benches directory, which includes both Rust benchmark code and a Python plotting script.
• This module validates performance (comparing against other libraries, as mentioned in the README).
d. Test Suite:
• Present in the tests directory (forward.rs, inverse.rs).
• Verifies correctness and consistency of the FFT implementations.
e. CI/CD and Build Configurations:
• Includes GitHub workflows (.github/workflows/rust.yml) and Cargo configurations (.cargo/config.toml).
• Although not part of runtime architecture, these are important for continuous integration and reliable builds.
f. Assets:
• Any support artifacts such as the assets folder (e.g., log_comparison.png) that document performance comparisons.
Relationships and Interactions
• The core FFT library (API) relies on the proc-macro provided by the monarch-derive crate to generate its specialized FFT implementations at compile time.
• Client code (users of the library) directly calls the public methods (fft/ifft) exposed by the core library.
• The benches and tests are separate consumers of the library, aimed at performance validation and correctness respectively.
• The CI configurations ensure that any change in these components is automatically tested and built, emphasizing safe code practices (e.g., no unsafe code).
Architectural Patterns and Design Principles
• Modularity: The project is divided into clearly defined crates, each with a focused responsibility.
• Compile-Time Code Generation: Using proc-macros to unroll loops and generate optimal FFT kernels.
• Const-Evaluation and SIMD Optimization: The design leverages compile-time knowledge of FFT sizes to optimize performance.
• Zero Unsafe Code Emphasis: The library is designed to be completely safe in Rust.
• Separation of Concerns: Clear distinction between core functionality, code generation, and benchmarking/testing.
Relevant Technologies and Frameworks
• Rust and Cargo workspaces.
• Rust proc-macros for code generation.
• SIMD instructions (as detailed in the README for performance) and Rust’s const-evaluation.
• CI/CD integrations with GitHub Actions.
• Python scripting in benchmarks (for plot generation).