ifsnop / mysqldump-php

PHP version of mysqldump cli that comes with MySQL
https://github.com/ifsnop/mysqldump-php
GNU General Public License v3.0
1.25k stars 300 forks source link

Remove unnecessary call_user_func() to be faster #278

Closed staabm closed 2 months ago

staabm commented 9 months ago

with a test script of

<?php // test.php

error_reporting(E_ALL);

require_once __DIR__ . '/vendor/autoload.php';

use Ifsnop\Mysqldump as IMysqldump;

$date = date('Ymd');
$dumpSettings = array(
    'compress' => IMysqldump\Mysqldump::NONE,
    'no-data' => false,
    'add-drop-table' => true,
    'single-transaction' => true,
    'lock-tables' => false,
    'add-locks' => true,
    'extended-insert' => true,
    'disable-foreign-keys-check' => true,
    'skip-triggers' => false,
    'add-drop-trigger' => true,
    'databases' => true,
    'add-drop-database' => true,
    'hex-blob' => true,
    'include-tables' => array('my-table'), // add a table name here
);

$dump = new IMysqldump\Mysqldump("mysql:host=192.168.54.10:33065;dbname=clx_erp", "clxerp_user", "P8_Zyv3_Z3-S1", $dumpSettings);
$dump->setTransformTableRowHook(function ($tableName, $row) {
    return $row;
});
$dump->start("backup$date.sql");

before this PR

mstaab@mst22:/cluster/www/www/www/mysqldump-php$ time php test2.php

real    0m13.046s
user    0m9.917s
sys     0m2.003s
mstaab@mst22:/cluster/www/www/www/mysqldump-php$ time php test2.php

real    0m13.027s
user    0m9.838s
sys     0m2.144s

after this PR

mstaab@mst22:/cluster/www/www/www/mysqldump-php$ time php test2.php

real    0m12.648s
user    0m9.613s
sys     0m1.994s

mstaab@mst22:/cluster/www/www/www/mysqldump-php$ time php test2.php

real    0m12.883s
user    0m9.838s
sys     0m2.008s
ifsnop commented 2 months ago

There should be no difference between calling call_user_func() or invoking the function directly, since both of them get the same compiled code.

staabm commented 2 months ago

AFAIK it depends on the php-version. but nowadays it should work like you said most of the time