fix(@angular/build): flush perf timings from within the diagnostic worker#33414
Open
arturovt wants to merge 1 commit into
Open
fix(@angular/build): flush perf timings from within the diagnostic worker#33414arturovt wants to merge 1 commit into
arturovt wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces cumulative duration resetting and logging around the diagnostic collection phase in AngularCompilation.diagnoseFiles, along with a new test suite to verify this behavior. The review feedback points out a critical issue: running this lifecycle on the main thread (when parallel compilation is disabled) would prematurely clear and print cumulative timings. The reviewer suggests restricting this profiling lifecycle to worker threads by checking isMainThread from node:worker_threads via a helper method shouldFlushPerformanceTimings(), which can also be overridden in tests to maintain test coverage.
…rker When ParallelCompilation is used, diagnoseFiles() runs in a worker thread. The cumulative duration Map (populated by profileSync(..., cumulative=true) inside collectDiagnostics) lives in that worker's module memory — the main thread's logCumulativeDurations() call never sees it, so timings were silently dropped. Fix by owning the full reset→log cycle inside diagnoseFiles() itself, with a try/finally to guarantee the flush even if diagnostics throw. Also adds unit tests covering call order, the empty-diagnostics path, result correctness, and the throw-still-flushes guarantee.
ce45591 to
aa0039d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When ParallelCompilation is used, diagnoseFiles() runs in a worker thread. The cumulative duration Map (populated by profileSync(..., cumulative=true) inside collectDiagnostics) lives in that worker's module memory — the main thread's logCumulativeDurations() call never sees it, so timings were silently dropped.
Fix by owning the full reset→log cycle inside diagnoseFiles() itself, with a try/finally to guarantee the flush even if diagnostics throw.
Also adds unit tests covering call order, the empty-diagnostics path, result correctness, and the throw-still-flushes guarantee.
Result: