Repository navigation
Open
Description
- Use version \x00\x00\x00\x03 when this is stable
- Avoid wasting space emitting key representations when
array_is_list, i.e. when array keys are consecutive integers starting from 0 (have a fallback to start emitting unexpected keys with different values, if needed) - Allow more than one reference group to the same php value to be distinctly unserialized (e.g.
$x = new stdClass; $y = $x; igbinary_serialize([&$x, &$x, &$y, &$y]);)
(TODO: I forget the exact issue. Was that fixed already for the general case, or was the issue mixes of references and non-references) - Shorter representations for 1-character interned strings
- Shorter representations for private properties of serialized class
\x00$classname\x00$propname(and protected properties\x00*\x00$propname) (keys for parent classes and traits would be serialized normally) - Don't bother creating string ids for empty strings (EDIT: that's already part of the v2 design?) and 1-character strings that would already be interned in modern php versions (support reusing per-request in RINIT in igbinary itself if practical for php versions without ZSTR_CHAR guaranteed to exist)
Opt-in can be done on per-serializer settings, to allow any migrations (e.g. redis, memcached) to be done separately.
The unserializer should recognize v3 from the header
Related to phpredis/phpredis#2194
Updates (October 19):
Implementation is broken/incomplete and the v3 serialization format will be changed, found on the fork branch igbinary-v3-format
- Shorter representations for very small non-negative integers (e.g. 0..7 can be X+(0..7)) is an idea I've seen in several other binary protocol formats, useful for
['key' => 1, 'x' => 0]where integers are used instead of booleans, or just from most integers being small (e.g. counts) when averaged out over common use cases - Still haven't implemented for serializing lists
- Still haven't finished adding a way to represent creating a new reference group to the same php object for the general case
- Haven't benchmarked this yet
Metadata
Metadata
Assignees
Labels
No labels
Activity
tricky commentedon Oct 19, 2022
This seems reasonable to me.
Additionally consider specific types for short integer indexed arrays (0..3), though this should be guided by real numbers rather than a gut feeling that short lists are common.
TysonAndre commentedon Oct 23, 2022
One other optimization to look into would be to indicate for strings whether or not they should be added to the strings table during serialization, and use that to improve performance when unserializing.
It may help for extremely large data, but I'm less certain of this for small objects that fit in cache (e.g. due to branch prediction costs)
If there's a lot of small strings in arrays that are only used once (megabytes), for example, unserializing igbinary protocol v2 currently
E.g. an example use case might be storing a distinct set of object ids as serialized data in memcached (
[$id1 => true, $id2 => true]) alone or as part of an objectWhether this should actually reindex the string ids would depend on the unserializer performance in practice
Whether it's worth it in practice would probably depend on how it works for normal object sizes
In that example, the
type & 1would indicate if null should be saved to the strings table insteadThis would also reduce memory usage
__unserializeaccepted distinct temporary strings but didn't keep the reference to it around permanentlyTysonAndre commentedon Oct 23, 2022
For use cases where there's a lot of strings being unserialized that only occur once, igbinary performs worse than unserialize in benchmarks I've run, e.g.
https://github.com/krakjoe/apcu/pull/454#issuecomment-1288182980, I expect probably because igbinary has to perform a second pass through all the strings in the string table and free themTysonAndre commentedon Oct 23, 2022
Also, when
igbinary.compact_strings=off, the v3 protocol could immediately use the_norefvariants of all of those string types[-]Idea: New opt-in serialization format to save space[/-][+]Idea: New v3 opt-in serialization format to save space[/+]