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

Most upvoted comments

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:

v5.0.16
first run with cold/empty cache: 15.171237945557, misses: 100000
second run with hot/full cache: 0.80318379402161, misses: 0
first run with cold/empty cache: 15.268904924393, misses: 100000
second run with hot/full cache: 0.82464909553528, misses: 0
first run with cold/empty cache: 15.326946020126, misses: 100000
second run with hot/full cache: 0.81104683876038, misses: 0

v6.0.1
first run with cold/empty cache: 17.714466094971, misses: 100000
second run with hot/full cache: 1.2769951820374, misses: 0
first run with cold/empty cache: 17.475311994553, misses: 100000
second run with hot/full cache: 1.1392340660095, misses: 0
first run with cold/empty cache: 18.510245084763, misses: 100000
second run with hot/full cache: 1.3172750473022, misses: 0

v6.0.2
first run with cold/empty cache: 16.973572015762, misses: 100000
second run with hot/full cache: 0.86043882369995, misses: 0
first run with cold/empty cache: 16.6197681427, misses: 100000
second run with hot/full cache: 0.84666991233826, misses: 0
first run with cold/empty cache: 16.184941053391, misses: 100000
second run with hot/full cache: 0.84634685516357, misses: 0

It’s better, that not quite back to v5

Ok, got it. Thanks a lot for your support so far @Geolim4 !