Skip to content

Conversation

@moreal
Copy link
Contributor

@moreal moreal commented Jan 13, 2026

This pull request was extracted from PR #6704. Since it will be squashed and merged, I thought it would be better to submit it separately in case we need to partially revert it later. Of course, there are also parts I'd like to merge first.

Summary by CodeRabbit

  • New Features

    • Added optional performance instrumentation feature that can be enabled to monitor operations.
  • Chores

    • Updated feature flag dependencies and integrated instrumentation support into JSON parsing components for enhanced performance monitoring.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 13, 2026

📝 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 configuration
Cargo.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 infrastructure
crates/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 instrumentation
crates/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 ⚠️ Warning 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

📥 Commits

Reviewing files that changed from the base of the PR and between bb57724 and 9e4ec0d.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • Cargo.toml
  • crates/stdlib/Cargo.toml
  • crates/stdlib/src/json.rs
  • crates/stdlib/src/lib.rs
  • crates/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 running cargo fmt to 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.rs
  • crates/stdlib/src/json.rs
  • crates/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-it follows the existing pattern used for other features like threading and 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-it feature is enabled. The _guard naming 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 using pub(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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@fanninpm
Copy link
Contributor

CI fails for reasons unrelated to this PR.

Copy link
Member

@youknowone youknowone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@youknowone
Copy link
Member

I wished those flaky tests were fixed by yesterday patches 😂

@youknowone youknowone merged commit 49e6931 into RustPython:main Jan 14, 2026
11 of 13 checks passed
terryluan12 pushed a commit to terryluan12/RustPython that referenced this pull request Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants