Repository navigation
perf(profiling): build code provenance in the background at scheduler start - #20611
vlad-scherbich wants to merge 4 commits into
Conversation
❌ ErrorsYour PR has failed checks. Please review the issues below and take necessary action before merging. 🚦 7 Pipeline jobs failed
ℹ️ InfoNo other issues found (see more)🧪 All tests passed Useful? React with 👍 / 👎 This comment will be updated automatically if new data arrives.🔗 Commit SHA: b2c02d3 | Docs | View more details | Give us feedback! |
Circular import analysis
|
Dependency direction analysis
|
Codeowners resolved asResolved from the full PR diff against |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8e7658d173
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
Description says this moves the cost to Profiler.start; I haven't read the code but if it is true it is not better. Users can manage their Profiler instance themselves, meaning them calling Profiler.start may block (for a long time, e.g. in dogweb) so this is not better than what we have today and from a user's perspective arguably worse.
Can we avoid doing it on the main thread maybe? (I guess it's hard to "fix" because it has to be a Python thread no matter what?)
There was a problem hiding this comment.
I'll put this PR back in draft while waiting on testing to come back, which will show concrete deltas.
|
This pull request has been automatically closed after a period of inactivity. |
There was a problem hiding this comment.
I see this has been auto-closed; I believe this shouldn't be an issue anymore now that Gab has rewritten the logic in Rust!
The first upload builds the code provenance file when the on-disk cache is cold, and that build waits for the installed packages scan. A process that exits before its first periodic upload paid for it in the shutdown flush. Resolving it synchronously in Scheduler._start_service only moved the stall onto Profiler.start, which waits for the scheduler to start. Start the build on a one-shot background thread instead, so neither start nor the exit flush waits for it when the process lives long enough for it to finish. ddup.upload stays the consumer and reuses the memoized path; if it runs first it builds the file itself.
d247339 to
e104ef9
Compare
BenchmarksBenchmark execution time: 2026-11-03 19:01:15 Comparing candidate commit b2c02d3 in PR branch Found 5 performance improvements and 0 performance regressions! Performance is the same for 573 metrics, 10 unstable metrics, 1 flaky benchmarks without significant changes.
|
The file lock only keeps out other processes. With the background build from the scheduler, a flush in the same process can build the file at the same time; both wrote the same temp file and the second rename failed, so that caller got no provenance file. Use one temp file per thread. Add tests for a flush during the background build and for a fork waiting on it.
The per-thread cache temp file and the scheduler tests on this branch left those names untyped.
Description
ddup.uploadbuilds the code provenance file on its first call. A process that exits before its first periodic upload does that in the shutdown flush, and on a cold cache that includes the installed-packages scan. #20808 made the scan native but did not remove the Python provenance build.The scheduler now builds the file once on a background thread after its periodic worker starts.
start()andstop()do not wait for it. Nothing runs when code provenance is disabled.Each thread now writes its own temp file. The file lock does not keep out a second thread of the same process, so a flush building at the same time as the background thread could lose the rename and upload without provenance.
Testing
tests/profiling/test_scheduler.pyandtest_code_provenance.pycover the background build, the disabled case, build failure, a flush during the build, a fork during the build, and two builders at once. The background-build, flush, fork, and two-builder tests fail on main.Risks
If the process exits before the background build finishes, the shutdown flush still builds the file itself. A fork during a cold build waits for the build to finish.
Additional Notes
None.