Skip to content

perf: defer API run creation until first emission upload (3/4)#1253

Open
davidberenstein1957 wants to merge 1 commit into
davidberenstein1957/perf-2-hardware-cachefrom
davidberenstein1957/perf-3-lazy-api-run
Open

perf: defer API run creation until first emission upload (3/4)#1253
davidberenstein1957 wants to merge 1 commit into
davidberenstein1957/perf-2-hardware-cachefrom
davidberenstein1957/perf-3-lazy-api-run

Conversation

@davidberenstein1957

@davidberenstein1957 davidberenstein1957 commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

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

cc @inimaz — small, isolated API write-path change from the #1246 split.

Defers the POST /runs API call until the first emission is actually uploaded, so online trackers with API output enabled no longer block on run creation during startup:

  • CodeCarbonAPIOutput uses create_run_automatically=False
  • _ensure_api_run() creates the run lazily on first live_out / out call

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

Mocked geo/cloud/API network; measures EmissionsTracker(save_to_api=True) cold start():

Metric #1251 + #1252 + this PR Notes
API tracker start() avg 407 ms 369 ms ~9% faster — avoids blocking POST /runs at startup
Tracker __init__ / warm lifecycle unchanged unchanged No change expected — run creation deferred to first upload

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. This PR — lazy API run creation
  4. perf: speed up CLI monitor startup and fix wrapped commands (4/4) #1254 — CLI monitor startup

CI / quality

Test plan

  • Reviewer: online tracker with API output still uploads emissions correctly

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.28%. Comparing base (00817d8) to head (928621d).

Additional details and impacted files
@@                            Coverage Diff                             @@
##           davidberenstein1957/perf-2-hardware-cache    #1253   +/-   ##
==========================================================================
  Coverage                                      89.27%   89.28%           
==========================================================================
  Files                                             48       48           
  Lines                                           4757     4761    +4     
==========================================================================
+ Hits                                            4247     4251    +4     
  Misses                                           510      510           

☔ 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-2-hardware-cache branch from 1f759d9 to 9d1c656 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
Skip POST /runs during tracker startup and create the run lazily on the
first live_out/out call when an experiment id is configured.

Co-authored-by: Cursor <cursoragent@cursor.com>
@davidberenstein1957 davidberenstein1957 force-pushed the davidberenstein1957/perf-2-hardware-cache branch from 9d1c656 to 00817d8 Compare June 22, 2026 07:49
@davidberenstein1957 davidberenstein1957 force-pushed the davidberenstein1957/perf-3-lazy-api-run branch from 07b82eb to 928621d 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