Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In smart_delete_backups()
, there is a while loop that could be made more efficient with some simple math:
// Increment time till we get within one period time span of the period
// start time. This keeps all the different period starts aligned.
while ($time < $period_start_time) {
$time += $period['delta'];
}
Rather than adding in a while loop, you can subtract the values in the condition and divide by delta to see exactly how many times the delta will be added, then multiply by the delta and add it all at once. This gives the same result, but is noticeably faster:
if ($time < $period_start_time) {
$time += ((int) ceil(($period_start_time - $time) / $period['delta'])) * $period['delta'];
}
Depending on how old the $oldest_file_time
is, this can easily shave an entire second off the execution time.
Comment | File | Size | Author |
---|---|---|---|
#6 | backup_migrate-schedule-performance-3060997-6.patch | 953 bytes | solideogloria |
|
Comments
Comment #2
solideogloria CreditAttribution: solideogloria commentedComment #3
solideogloria CreditAttribution: solideogloria commentedGo here for a quick PHP runtime comparison in an online interpreter (TIO - Try It Online)
Comment #4
DamienMcKennaThat's some good sleuthing, thank you!
Comment #5
BrankoC CreditAttribution: BrankoC as a volunteer commentedThe preceding comment in the code makes slightly less sense in the patched version (mainly because of the 'till', which suggests a process to me).
How about?
Comment #6
solideogloria CreditAttribution: solideogloria commentedSounds good to me. Updated patch.
Comment #8
DamienMcKennaCommitted. Thank you.