Skip to content

perf: speed up CLI monitor startup and fix wrapped commands (4/4)#1254

Open
davidberenstein1957 wants to merge 1 commit into
davidberenstein1957/perf-3-lazy-api-runfrom
davidberenstein1957/perf-4-cli-monitor
Open

perf: speed up CLI monitor startup and fix wrapped commands (4/4)#1254
davidberenstein1957 wants to merge 1 commit into
davidberenstein1957/perf-3-lazy-api-runfrom
davidberenstein1957/perf-4-cli-monitor

Conversation

@davidberenstein1957

@davidberenstein1957 davidberenstein1957 commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

Part 4/4 of the tracker performance stack. Depends on #1251#1252#1253.

cc @inimaz — final CLI layer of the #1246 split. Merging #1251#1252#1253 → this PR restores the full change set.

Speeds up codecarbon monitor startup and fixes wrapped-command delegation:

  • Lazy-import heavy CLI dependencies (questionary, requests, tracker classes, etc.)
  • Add --log-level option to codecarbon monitor (default: error)
  • Fix wrapped command parsing: strip nested monitor / -- tokens before exec
  • Update CLI reference docs for --log-level default

Benchmarks (measured locally, offline Mac ARM, 2026-06-21)

Full stack cumulative vs master:

Metric master Full stack (this PR tip) Δ vs master
Tracker __init__ p50 190 ms 1.0 ms ~99% faster
Cold lifecycle p50 (init→start→stop) 1,685 ms 433 ms ~74% faster (~4×)
Warm lifecycle best (same process) 1,565 ms 5.9 ms ~265× faster
CLI monitor subprocess p50 850 ms 643 ms ~24% faster

Stack

  1. perf: defer tracker initialization and slim import path (1/4) #1251 — lazy initialization & import slimming
  2. perf: cache hardware detection and optimize warm-path reuse (2/4) #1252 — hardware detection cache & warm-path reuse
  3. perf: defer API run creation until first emission upload (3/4) #1253 — lazy API run creation
  4. This PR — CLI monitor startup & UX

CI / quality

  • pre-commit run --all-files — passed (autoflake, isort, black, flake8)
  • pytest tests/cli/ — 59 passed
  • Full suite — 535 passed locally (CODECARBON_ALLOW_MULTIPLE_RUNS=True pytest --ignore=tests/test_viz_data.py -m 'not integ_test' tests/)

Test plan

  • Manual: codecarbon monitor --offline --country-iso-code FRA -- sleep 1
  • Manual: codecarbon monitor --offline --country-iso-code FRA --log-level debug -- python train.py

Replaces

Split from #1246.

@codecov

codecov Bot commented Jun 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.35%. Comparing base (928621d) to head (11f3f20).

Additional details and impacted files
@@                             Coverage Diff                             @@
##           davidberenstein1957/perf-3-lazy-api-run    #1254      +/-   ##
===========================================================================
+ Coverage                                    89.28%   89.35%   +0.06%     
===========================================================================
  Files                                           48       48              
  Lines                                         4761     4771      +10     
===========================================================================
+ Hits                                          4251     4263      +12     
+ Misses                                         510      508       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@davidberenstein1957

Copy link
Copy Markdown
Collaborator Author

@inimaz#1246 has been split into this 4-PR stack for easier review. Benchmarks in the description are measured locally (Mac ARM, 2026-06-21); pre-commit and tests pass on each branch. Please start with #1251.

@davidberenstein1957 davidberenstein1957 force-pushed the davidberenstein1957/perf-4-cli-monitor branch from 5fc6acd to e933dea Compare June 21, 2026 14:37
@davidberenstein1957 davidberenstein1957 force-pushed the davidberenstein1957/perf-3-lazy-api-run branch from a85be35 to 07b82eb Compare June 21, 2026 14:37
Lazy-import heavy CLI dependencies, add --log-level to monitor, and strip
nested monitor/-- tokens when delegating to wrapped user commands.

Co-authored-by: Cursor <cursoragent@cursor.com>
@davidberenstein1957 davidberenstein1957 force-pushed the davidberenstein1957/perf-3-lazy-api-run branch from 07b82eb to 928621d Compare June 22, 2026 07:49
@davidberenstein1957 davidberenstein1957 force-pushed the davidberenstein1957/perf-4-cli-monitor branch from e933dea to 11f3f20 Compare June 22, 2026 07:49
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.

1 participant