Add spans to rustpython-stdlib JSON for flamegraph analysis by moreal · Pull Request #6722 · RustPython/RustPython
📝 Walkthrough
Walkthrough
The changes introduce flame profiling instrumentation across the codebase by adding a "flame-it" feature flag, creating a conditional flame_guard! macro, and instrumenting the JSON parser with profiling calls to measure execution performance.
Changes
| Cohort / File(s) | Summary |
|---|---|
Feature and dependency configurationCargo.toml, crates/stdlib/Cargo.toml |
Added "flame-it" feature flag to workspace manifest and stdlib crate; introduced optional "flame" crate dependency in stdlib; workspace feature now depends on "rustpython-stdlib/flame-it" alongside existing dependencies |
Profiling macro infrastructurecrates/stdlib/src/lib.rs, crates/stdlib/src/macros.rs |
Declared new pub(crate) macros module with #[macro_use] attribute; implemented exportable flame_guard! macro that conditionally wraps ::flame::start_guard() when "flame-it" feature is enabled |
Profiling instrumentationcrates/stdlib/src/json.rs |
Added flame_guard! calls to JsonScanner::parse, JsonScanner::parse_number, encode_string, and scanstring functions for profiling coverage without altering logic or signatures |
Estimated code review effort
🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
🔥 A flame so bright, we trace the way,
Through JSON paths, both night and day—
With guards we start, with guards we shine,
Performance secrets, line by line! 🐰✨
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
✅ Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title accurately summarizes the main change: adding flame profiling spans to the JSON module in rustpython-stdlib for flamegraph analysis, which is reflected throughout all the code changes (macro definition, feature flags, and instrumentation points). |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing touches
- 📝 Generate docstrings
📜 Recent review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (5)
Cargo.tomlcrates/stdlib/Cargo.tomlcrates/stdlib/src/json.rscrates/stdlib/src/lib.rscrates/stdlib/src/macros.rs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.rs: Follow the default rustfmt code style by runningcargo fmtto format Rust code
Always run clippy to lint code (cargo clippy) before completing tasks and fix any warnings or lints introduced by changes
Follow Rust best practices for error handling and memory management
Use the macro system (pyclass,pymodule,pyfunction, etc.) when implementing Python functionality in Rust
Files:
crates/stdlib/src/macros.rscrates/stdlib/src/json.rscrates/stdlib/src/lib.rs
🧠 Learnings (1)
📚 Learning: 2025-12-27T14:03:49.034Z
Learnt from: CR
Repo: RustPython/RustPython PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-27T14:03:49.034Z
Learning: Applies to **/*.rs : Use the macro system (`pyclass`, `pymodule`, `pyfunction`, etc.) when implementing Python functionality in Rust
Applied to files:
crates/stdlib/src/lib.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: Run snippets and cpython tests on wasm-wasi
- GitHub Check: Run tests under miri
- GitHub Check: Run rust tests (ubuntu-latest)
- GitHub Check: Run snippets and cpython tests (macos-latest)
- GitHub Check: Run rust tests (windows-2025)
- GitHub Check: Run snippets and cpython tests (windows-2025)
- GitHub Check: Ensure compilation on various targets
- GitHub Check: Run rust tests (macos-latest)
- GitHub Check: Check the WASM package and demo
- GitHub Check: Run snippets and cpython tests (ubuntu-latest)
- GitHub Check: Check Rust code with clippy
🔇 Additional comments (5)
Cargo.toml (1)
18-18: LGTM!The feature propagation to
rustpython-stdlib/flame-itfollows the existing pattern used for other features likethreadingand aligns with the PR's goal of enabling flamegraph analysis for the stdlib.crates/stdlib/Cargo.toml (1)
25-25: LGTM!The feature definition and optional dependency follow the established patterns in this manifest. Using workspace-backed versioning ensures consistency across the project.
Also applies to: 37-37
crates/stdlib/src/macros.rs (1)
1-7: LGTM!The macro correctly uses conditional compilation to emit a flame guard only when the
flame-itfeature is enabled. The_guardnaming convention appropriately suppresses unused variable warnings, and the RAII pattern ensures proper timing capture when the guard goes out of scope.crates/stdlib/src/lib.rs (1)
11-12: LGTM!The module declaration with
#[macro_use]follows the established pattern in this file and correctly scopes the macro availability to within the crate usingpub(crate).crates/stdlib/src/json.rs (1)
77-77: LGTM!The profiling guards are strategically placed at key JSON parsing and encoding entry points. The consistent naming convention (
Type::method/module::function) will produce clear flamegraph labels, and using static string literals avoids runtime allocation overhead.Also applies to: 157-157, 218-218, 259-259
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.