Skip to content

Commit 6426f6f

Browse files
authored
GC target decay, break on convergence (#429)
Prior to this, since the original last updated time was the epoch (0), the first GC, this loop would run over 25 million times. With this change, that goes down to 57.
1 parent 61f2bcc commit 6426f6f

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

sdlib/d/gc/collector.d

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ private:
147147
/**
148148
* Track the targets to meet before collecting.
149149
*/
150-
ulong lastTargetAdjustement;
150+
ulong lastTargetAdjustment;
151151

152152
size_t nextTarget = DefaultHeapSize;
153153

@@ -191,13 +191,21 @@ private:
191191
auto interval =
192192
max(lastCollectionStop - lastCollectionStart, 100 * Millisecond);
193193

194-
while (now - lastTargetAdjustement >= interval) {
194+
while (now - lastTargetAdjustment >= interval) {
195195
auto delta = nextTarget - lastHeapSize;
196196
delta -= delta >> lgTargetDecay;
197197
delta += lastHeapSize >> (lgTargetDecay + lgMinOverhead);
198-
nextTarget = lastHeapSize + delta;
199198

200-
lastTargetAdjustement += interval;
199+
auto newTarget = lastHeapSize + delta;
200+
if (newTarget == nextTarget) {
201+
// Limit reached.
202+
lastTargetAdjustment = now;
203+
break;
204+
}
205+
206+
nextTarget = newTarget;
207+
208+
lastTargetAdjustment += interval;
201209
}
202210

203211
auto currentHeapSize = Arena.computeUsedPageCount();
@@ -240,7 +248,7 @@ private:
240248
target = max(target, tbaseline);
241249
target = min(target, tpeak);
242250

243-
lastTargetAdjustement = lastCollectionStop;
251+
lastTargetAdjustment = lastCollectionStop;
244252
nextTarget = max(target, minHeapSize);
245253
}
246254
}

0 commit comments

Comments
 (0)