Performance & CI Benchmarking
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
Hesabyar utilizes a multi-layered benchmarking strategy to ensure high performance and prevent regressions across its Kotlin-based Android application and its shared Rust core (hesabyar-core). Performance monitoring is integrated into the Continuous Integration (CI) pipeline, allowing developers to track the impact of changes on critical business logic such as financial calculations, Persian Natural Language Processing (NLP), and calendar conversions.
The project employs three primary benchmarking tools: CodSpeed for CI-integrated performance tracking, JMH (Java Microbenchmark Harness) for JVM-based Kotlin logic, and Criterion for the native Rust logic. This approach ensures that "hot" code paths, such as date conversions and transaction parsing, meet the efficiency requirements necessary for a responsive mobile experience.
Sources: README.md:21-26, README.md:154-159, rust/hesabyar-core/README.md:6-18
Benchmarking Architecture
The benchmarking infrastructure is split by technology stack. Native Rust logic is benchmarked within the rust/hesabyar-core/benches directory, while JVM-based benchmarks reside in the benchmarks/ module.
The diagram shows how the benchmarking tools interface with the different layers of the Hesabyar project.
Sources: README.md:154-159, benchmarks/src/jmh/kotlin/io/github/mojri/hesabyar/benchmarks/JalaliCalendarBenchmark.kt:15-20
Rust Core Benchmarks (Criterion)
The hesabyar-core module uses Criterion to measure the performance of platform-independent logic. These benchmarks are critical because the Rust core handles heavy computational tasks migrated from the JVM for better performance.
Key Benchmark Suites
The Rust benchmarks cover the following areas:
- NLP & Parser: Measures the speed of
parse_amountandcontains_moneyusing Persian strings. - Calendar: Benchmarks
gregorian_to_jalaliand its inverse. - Advisory & Analytics: Evaluates complex logic like
get_offline_budget_adviceandcalculate_financial_health_scoreover datasets of 100+ transactions. - Search: Tests full-text search relevance scoring across 1,000 transactions.
- Crypto: Measures AES-256-GCM encryption/decryption and checksum speeds for small and large backup payloads.
| Benchmark Group | Functions Tested | Dataset Size |
|---|---|---|
parser | parse_amount, contains_money | Single strings |
budget_advice | get_offline_budget_advice, calculate_financial_health_score | 100 Transactions |
search | search_transactions | 1,000 Transactions |
crypto | encrypt_backup, decrypt_backup, compute_checksum | ~1,000 Transactions |
Sources: rust/hesabyar-core/benches/parser_bench.rs:16-160, rust/hesabyar-core/README.md:69-74
Implementation Example: Search Benchmarking
fn bench_search(c: &mut Criterion) {
let transactions: Vec<Transaction> = (0..1000)
.map(|i| Transaction {
// ... transaction initialization ...
description: format!("\u{062E}\u{0631}\u{06CC}\u{062F} \u{0628}\u{0631}\u{0642} {}", i),
// ...
})
.collect();
c.bench_function("search_text_1000tx", |b| {
b.iter(|| search_transactions(&transactions, &text_query))
});
}
Sources: rust/hesabyar-core/benches/parser_bench.rs:65-98
JVM Benchmarks (JMH)
JVM benchmarks focus on arithmetic-heavy pure-Kotlin routines that run frequently during UI rendering, such as Jalali calendar conversions. These are kept self-contained in the benchmarks/ module to measure platform-independent performance without the overhead of the Android environment or the Rust bridge.
Calendar Benchmarking
The JalaliCalendarBenchmark class tracks the average time for gregorianToJalaliLocal conversions, which is triggered whenever transactions or reports are rendered.
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Benchmark)
open class JalaliCalendarBenchmark {
@Benchmark
fun gregorianToJalali(): JalaliCalendarHelper.JalaliDate =
JalaliCalendarHelper.gregorianToJalaliLocal(2024, 6, 27)!!
}
Sources: benchmarks/src/jmh/kotlin/io/github/mojri/hesabyar/benchmarks/JalaliCalendarBenchmark.kt:15-32
Execution & CI Integration
Benchmarking is automated via CI, specifically using CodSpeed to detect regressions in every Pull Request.
Execution Commands
| Task | Command | Environment |
|---|---|---|
| Run JVM Benchmarks | cd benchmarks && ./gradlew jmh --no-daemon | JVM / Local |
| Run Rust Benchmarks | cd rust/hesabyar-core && cargo bench | Native / Local |
| Regression Tracking | Automatic on PR via GitHub Actions | CI (CodSpeed) |
Performance Verification Workflow
Developers are encouraged to verify performance as part of the mandatory post-modification workflow, especially when touching the Rust core.
The sequence shows the automated feedback loop for performance monitoring during the development cycle.
Sources: README.md:154-165, AGENTS.md:67-75, AGENTS.md:92-95
Summary
Performance and CI benchmarking in Hesabyar provide a robust defense against computational slowdowns. By leveraging JMH for Kotlin and Criterion for Rust, the project ensures that its high-frequency logic—specifically Jalali date arithmetic and Persian NLP—remains optimized for mobile use. Integration with CodSpeed further automates this process, making performance a first-class citizen in the development lifecycle.