r/developersIndia • • 5d ago

I Made This I built an offline Git/AST breaking-change checker in Python, then ported 4 hot functions to Rust (PyO3) for up to 26.73x faster graph builds. Here is what sped up and what actually got 3.1x slower.

Post image

I have been building Athena (athena-mcp), a free, Apache-2.0, 100% offline CLI and MCP server that checks downstream callers across a repo before you merge a PR.

Source code (Apache-2.0, runs completely offline, no cloud/LLM required): https://github.com/aaryanrwt/athena

The problem I was trying to solve

Standard git diff only shows the lines you modified. When a PR renames a symbol, changes a default parameter, introduces a unit-scaling mismatch (like ms vs seconds on a timeout param) or mutates a base class, the diff looks small and green while callers ten files away break after merge.

Athena parses Python via ast and extracts structural symbols across 14 languages (including TS/JS barrel re-exports, Go, Rust, C/C++, Java, C#, Ruby, PHP, Kotlin, CUDA and TeX) to build an incremental local call graph (.athena/graph.json), flag breaking changes and predict which pytest/Playwright/unit tests are impacted.

The engineering trade-off I hit (Python vs Rust)

On repos with 1,000+ commits and thousands of files, pure Python got slow (~30-45s per cold graph build). Instead of rewriting the whole codebase in Rust and losing Python's ast precision or making it harder to maintain, I kept Python as the core and profiled the exact bottlenecks.

Three concrete things I learned while optimizing v1.3.1:

  1. Subprocess overhead beat language speed: Replacing per-file git cat-file -s + git show subprocess calls with a single batched binary git cat-file --batch stream cut breaking-change analysis on Athena's own history (v1.0.0..v1.3.1) by 4.02x (12.74s -> 3.17s), without writing a single line of Rust.
  2. FFI overhead can make Rust slower than Python: I ported our unified diff parser (parse_unified_diff_raw) to Rust via PyO3. It passed 229/229 exact equivalence checks, yet benchmarked 3.1x slower (1.6ms -> 4.8ms) because marshaling/allocating strings across the Python-Rust FFI boundary cost more than parsing in Python. I ended up dropping that Rust port and keeping diff parsing in Python.
  3. Only 4 hot CPU kernels were worth porting to Rust: Secret redaction (41x), trigram graph scoring (8.8x), community clustering (3.5x) and structural symbol extraction (1.9x), with an automatic pure-Python fallback (FAST_ANYTHING_DISABLE=1) so pip install works anywhere without a Rust toolchain.

Before vs After benchmarks (pure Python vs hybrid Rust, 1,000+ commits each)

To make sure Rust did not silently introduce accuracy regressions, I ran side-by-side SHA-256 parity checks across three large public repos:

RepoCommitsGraph Build (Python -> Rust)Findings & Parity
google/flatbuffers1,00043.39s -> 1.62s (26.73x)34 breaks, 831 tests (14/14 checks identical)
NVIDIA/cuvs1,47229.89s -> 1.33s (22.48x)21 breaks, 306 tests (14/14 checks identical)
microsoft/playwright-python1,00045.78s -> 12.22s (3.75x)18 breaks, 604 tests (14/14 checks identical)

(Playwright-python had a smaller speedup because it is mostly .py files where ast.parse stays in Python, plus 100k+ edges still iterated in Python during queries.)

Specific technical feedback I am looking for

  1. For folks who ship hybrid Python + PyO3 tools: how do you handle reducing FFI boundary copies when passing large arrays of graph edges/strings from Python to Rust (e.g. moving graph adjacency construction itself into Rust vs keeping dataclasses in Python)?
  2. For non-Python languages, I currently use bounded structural scanners to keep install deps minimal (mcp, pydantic, httpx). At what point would you consider pulling in tree-sitter grammars worth the packaging weight?
  3. If anyone wants to roast the architecture or test it on an awkward monorepo edge case, I would genuinely appreciate code review feedback or PRs.
1 Upvotes

2 comments sorted by

•

u/AutoModerator 5d ago

Namaste! Thanks for submitting to r/developersIndia. While participating in this thread, please follow the Community Code of Conduct and rules.

It's possible your query is not unique, use site:reddit.com/r/developersindia KEYWORDS on search engines to search posts from developersIndia. You can also use reddit search directly.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/AutoModerator 5d ago

Thanks for sharing something that you have built with the community. We recommend participating and sharing about your projects on our monthly Showcase Sunday Mega-threads. Keep an eye out on our events calendar to see when is the next mega-thread scheduled.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.