phpfastcache: performance regression with v6
Configuration:
PhpFastCache version: 6.0.1 / 5.0.16 PHP version: 7.0 Operating system: Linux / Windows
Issue description:
I’ve updated a project to phpfastcache v6 and noticed a perfomance regression. The project is running on windows using the wincache driver with php 7.0. The perfomance regression compared to 5.0.16 is between 15%-25%.
I’ve created a test case, which I’ve ran under Linux as well using the files backend. The numbers are comparable. v5.0.16: first run with empty cache: 14.666780948639 second run with full cache: 0.75569796562195
v6.0.1: first run with empty cache: 17.629030942917 second run with full cache: 1.1219041347504
The code I used writes 100.000 entries and then reads them again from the cache:
<?php
require_once('vendor/autoload.php');
use \phpFastCache\CacheManager;
$cache = CacheManager::getInstance('files');
$cycles = 100000;
function compute_str($arg) {
$str = __FUNCTION__ . '-' . $arg . '-' . 'michael@test.example.com';
$key = str_replace(array('{', '}', '(', ')', '/', '\\', '@', ':'), '_', $str);
return $key;
}
function compute_md5($arg) {
$str = __FUNCTION__ . '-' . $arg . '-' . 'michael@test.example.com';
$key = md5($str);
return $key;
}
function compute_sha1($arg) {
$str = __FUNCTION__ . '-' . $arg . '-' . 'michael@test.example.com';
$key = sha1($str);
return $key;
}
function compute($arg) {
return compute_sha1($arg);
}
$before = microtime(true);
for ($i=0; $i<$cycles; $i++) {
$key = compute($i);
$cachedNum = $cache->getItem($key);
if (is_null($cachedNum->get())) {
$cachedNum->set($i*$i);
$cache->save($cachedNum);
} else {
$num = $cachedNum->get();
if ($num != $i*$i) {
print ("Something went wrong: " . $i . " -> " . $num);
}
}
}
$after = microtime(true);
$duration = $after - $before;
print ('first run with empty cache: ' . $duration . "\n");
$before = microtime(true);
for ($i=0; $i<$cycles; $i++) {
$key = compute($i);
$cachedNum = $cache->getItem($key);
if (is_null($cachedNum->get())) {
$cachedNum->set($i*$i);
$cache->save($cachedNum);
} else {
$num = $cachedNum->get();
if ($num != $i*$i) {
print ("Something went wrong: " . $i . " -> " . $num);
}
}
}
$after = microtime(true );
$duration = $after - $before;
print ('second run with full cache: ' . $duration . "\n");
$cache->clear();
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 34 (34 by maintainers)
Commits related to this issue
- Code optimization on huge loop operations as per #463 — committed to Geolim4/phpfastcache by Geolim4 7 years ago
- Merge pull request #478 from Geolim4/final Code optimization on huge loop operations as per #463 — committed to PHPSocialNetwork/phpfastcache by Geolim4 7 years ago
- Issue #463 // Fixed possible micro-performance issue — committed to Geolim4/phpfastcache by Geolim4 7 years ago
- Issue #463 // Fixed another possible micro-performance issue — committed to Geolim4/phpfastcache by Geolim4 7 years ago
I added
"minimum-stability" : "dev"to my composer.json, but that didn’t work. Apparently I’m doing something wrong. I see though that you you have released 6.0.2, so I ran a test against that:It’s better, that not quite back to v5
Ok, got it. Thanks a lot for your support so far @Geolim4 !