fix: ignore stale substep timestamps when computing target compilation duration#249
Merged
fortmarek merged 2 commits intoMobileNativeFoundation:masterfrom Apr 24, 2026
Conversation
bc8266e to
39f5c7b
Compare
pepicrft
approved these changes
Apr 24, 2026
…n duration For incremental builds, Xcode reuses substep entries from previous build sessions for files that don't need recompilation. Those substeps keep their original (older) timestamps and are not flagged `wasFetchedFromCache`. The previous logic in `addCompilationTimesToTarget` took the latest substep `compilationEndTimestamp` regardless of whether it actually ran in this build session, which produced a negative `compilationDuration` whenever the chosen substep predated the target's `startTimestamp`. Filter out such stale substeps by requiring `compilationEndTimestamp >= parent.startTimestamp` in both `addCompilationTimesToTarget` and `addCompilationTimesToApp`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Signed-off-by: fortmarek <marekfort@me.com>
Inline the new filter clause across two lines instead of expanding it into a four-line block, so the file stays at 400 lines (the SwiftLint file_length limit). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Signed-off-by: fortmarek <marekfort@me.com>
39f5c7b to
bf56c7c
Compare
This was referenced Apr 24, 2026
Merged
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.
Summary
addCompilationTimesToTarget(andaddCompilationTimesToApp) currently subtracttarget.startTimestampfrom the latest substep'scompilationEndTimestamp. For incremental Xcode builds this can produce a negativecompilationDurationbecause Xcode reuses substep entries from prior build sessions for files that didn't need recompilation. Those substeps keep their original (older) timestamps and are not flaggedwasFetchedFromCache, so the existing filter doesn't exclude them, and the chosen "last compile substep" can have ended long before the target started.This PR filters those stale substeps out by also requiring
compilationEndTimestamp >= parent.startTimestamp.Concrete example
A real
.xcactivitylogfrom an incremental build (404 targets, ~52s wall clock, only one target's sources had changed):compilationDurationThe single target with positive duration was the only one with source changes requiring real compilation; the rest correctly report 0. Without the fix, those 403 targets each report values around
-1118s, which downstream consumers (e.g. systems storingcompilationDurationas an unsigned integer) wrap into nonsensical huge numbers.Test plan
testParseTargetCompilationTimesIgnoresStaleSubstepscovering a target whose only substep ended before the target started; expectscompilationDuration == 0andcompilationEndTimestamp == startTimestamp.testParseTargetCompilationTimes,testParseAppCompilationTimes, andtestParseAppNoopCompilationTimesstill pass..xcactivitylogand confirmed allcompilationDurationvalues are non-negative.🤖 Generated with Claude Code