Skip to content

Commit a33ba56

Browse files
runningcodeclaude
andcommitted
perf(core): Use fixed-delay scheduling for performance collector
Switch the transaction collection timer from scheduleAtFixedRate to schedule. Fixed-rate scheduling fires rapid catch-up executions after a delay or GC pause, which the old code guarded against with a 10ms skip check. Fixed-delay scheduling spaces each collection 100ms after the previous one finishes, so the catch-up bursts cannot happen and the guard, its timestamp field, and the stale comment are no longer needed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 3594cd9 commit a33ba56

1 file changed

Lines changed: 1 addition & 10 deletions

File tree

sentry/src/main/java/io/sentry/DefaultCompositePerformanceCollector.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public final class DefaultCompositePerformanceCollector implements CompositePerf
2727

2828
private final @NotNull SentryOptions options;
2929
private final @NotNull AtomicBoolean isStarted = new AtomicBoolean(false);
30-
private long lastCollectionTimestamp = 0;
3130

3231
public DefaultCompositePerformanceCollector(final @NotNull SentryOptions options) {
3332
this.options = Objects.requireNonNull(options, "The options object is required.");
@@ -112,16 +111,8 @@ public void run() {
112111
new TimerTask() {
113112
@Override
114113
public void run() {
115-
long now = System.currentTimeMillis();
116-
// The timer is scheduled to run every 100ms on average. In case it takes longer,
117-
// subsequent tasks are executed more quickly. If two tasks are scheduled to run in
118-
// less than 10ms, the measurement that we collect is not meaningful, so we skip it
119-
if (now - lastCollectionTimestamp <= 10) {
120-
return;
121-
}
122114
timedOutTransactions.clear();
123115

124-
lastCollectionTimestamp = now;
125116
final @NotNull PerformanceCollectionData tempData =
126117
new PerformanceCollectionData(options.getDateProvider().now().nanoTimestamp());
127118

@@ -147,7 +138,7 @@ public void run() {
147138
}
148139
}
149140
};
150-
timer.scheduleAtFixedRate(
141+
timer.schedule(
151142
timerTask,
152143
TRANSACTION_COLLECTION_INTERVAL_MILLIS,
153144
TRANSACTION_COLLECTION_INTERVAL_MILLIS);

0 commit comments

Comments
 (0)