perf: defer tracker initialization and slim import path (1/4)#1251
Conversation
Lazy-load reference data, output handlers, hardware probing, and the emissions engine so tracker construction stays fast when work is deferred. Co-authored-by: Cursor <cursoragent@cursor.com>
Deferred hardware setup in PR 1 requires _ensure_hardware_ready() in tests that inspect tracker._hardware before start(). Co-authored-by: Cursor <cursoragent@cursor.com>
|
Test fix pushed: Verified locally: 504 passed, pre-commit clean. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1251 +/- ##
==========================================
+ Coverage 89.17% 89.39% +0.21%
==========================================
Files 47 47
Lines 4510 4565 +55
==========================================
+ Hits 4022 4081 +59
+ Misses 488 484 -4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
inimaz
left a comment
There was a problem hiding this comment.
Nice thanks for the split @davidberenstein1957 . I added a comment
Use TYPE_CHECKING import for pd so lazy loading stays fast while keeping return type annotations on get_cloud_emissions_data and get_cpu_power_data. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@inimaz — addressed your review comments on Verified locally on all 4 PR branches:
|
inimaz
left a comment
There was a problem hiding this comment.
LGTM thanks @davidberenstein1957 !
Summary
Part 1/4 of the tracker performance stack (replaces #1246).
cc @inimaz — split per your review feedback into smaller, reviewable PRs.
Defers expensive work until it is actually needed so tracker construction and
import codecarbonstay fast:DataSource(CSV/JSON on first access, not at import)output_methods=[]stop()when a sample was just taken (_measure_power_and_energy_if_stale)cpuinfo,arrow, and directoutput_methodsimportsBenchmarks (measured locally, offline Mac ARM, 2026-06-21)
Fresh Python subprocess per sample; baseline =
master.__init__p50init→start→stop)What this PR delivers: near-instant tracker construction. The big cold
start()win comes in #1252.Stack
CI / quality
pre-commit runon all changed files — passed (autoflake, isort, black, flake8)Test plan
output_methods=[]still measures on start/stopReplaces
Split from #1246.