Skip to content

Significant drop in performance of igbinary_unserialize() since 3.2.11 related to typed properties #371

@c-locksmith

Description

@c-locksmith

We have noticed a significant performance drop of igbinary_unserialize() when we upgraded from 3.2.9 to 3.2.12. It turned out that the issue was introduced with version 3.2.11 and specifically seems to be connected to the fixes to typed properties in Issue #363, as mentioned in the change log.

This is especially noticeable in our application, which serializes sets of complex PHP objects (using typed properties almost exclusively) into a cache, that is accessed during each request. We registered an increase in run time of igbinary_unserialize() of roughly 100%, which significantly impacted the performance of each request. The issue is at a similar level reproducible with this PHP script creating and serializing a bunch of trivial objects with an attribute that is either typed or untyped:

$runs = 1000;

// run test with untyped property

class TestUntypedProperty {
    public $str = 'x';
}

$arr = [];
for ($i = 0; $i < 10000; $i++) {
    $arr[] = new TestUntypedProperty();
}
$serializedUntyped = igbinary_serialize($arr);

$start = microtime(true);
for ($i = 0; $i < $runs; $i++) {
    igbinary_unserialize($serializedUntyped);
}
$end = microtime(true);
echo sprintf("avg unserialize with untyped attribute: %.10f\n", ($end - $start) / $runs);


// run test with typed property

class TestTypedProperty {
    public string $str = 'x';
}

$arr = [];
for ($i = 0; $i < 10000; $i++) {
    $arr[] = new TestTypedProperty();
}
$serializedTyped = igbinary_serialize($arr);

$start = microtime(true);
for ($i = 0; $i < $runs; $i++) {
    igbinary_unserialize($serializedTyped);
}
$end = microtime(true);
echo sprintf("avg unserialize with typed attribute:   %.10f\n", ($end - $start)/$runs);

While with igbinary version 3.2.9 the difference between the two test runs is hardly measurable, with version 3.2.12 the avg run time increases by a factor of 1.7x to 2x.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions