Skip to content

Commit 8a1b477

Browse files
authored
performance bottlenecks (#233)
2 parents b5ccb64 + 5e70eda commit 8a1b477

3 files changed

Lines changed: 4 additions & 6 deletions

File tree

PULL_REQUEST.md

Whitespace-only changes.

src/Phaseolies/Database/Entity/Query/InteractsWithBigDataProcessing.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ public function chunk($chunkSize, callable $processor, ?int $total = null): void
3838
$offset += $chunkSize;
3939

4040
// prevent memory leaks
41-
// unsetting and invoking garbage collection
4241
unset($chunkQuery, $results);
43-
if (gc_enabled()) {
44-
gc_collect_cycles();
45-
}
4642
}
4743
}
4844

src/Phaseolies/Http/Controllers/Controller.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,11 @@ protected function compileAndCache(string $actual, string $cache): void
487487
@unlink($tempFile);
488488
}
489489

490-
// Small delay before retry to avoid race conditions
490+
// Exponential backoff with jitter to prevent thundering herd
491491
if ($retries < self::MAX_COMPILE_RETRIES) {
492-
usleep(10000 * $retries); // 10ms, 20ms, 30ms
492+
$baseDelay = 10000 * (2 ** ($retries - 1)); // 10ms, 20ms, 40ms, 80ms
493+
$jitter = random_int(0, $baseDelay / 4); // ±25% jitter
494+
usleep($baseDelay + $jitter);
493495
}
494496
}
495497
}

0 commit comments

Comments
 (0)