Skip to content

(Enhancement/experimental) add new data types to aggressively serialize data #119

Open

Description

@TysonAndre

This would be serialized with a different igbinary version if the new serialization features were enabled (disable using this to serialize by default).

Proposals for this:

  • Private properties of LongClassName (private $_propName) are serialized as "\x00LongClassName\x00_propName" - Add a new string data type which will prepend the class name(not base classes) to the data ("\x00LongClassName\x00" . $remaining). Reject if not currently unserializing a class's property key. Insert the original string ("\x00LongClassName\x00_propName") into the string map.
  • Protected properties : Special case serialization of the string "\x00*\x00_propName" to avoid serializing the first 3 bytes
  • Base 64 encoding - Property names (and many array keys/string literals) usually only have letters in the range [a-zA-Z0-9_-] (64 unique values). In combination with the above special cases, serialize these differently (e.g. saves 6 bytes of a 24-byte ascii string. Ascii is frequently the only thing used for property names, though foreign characters are allowed. base 64 decode that if all of the characters are in that range, and store the original length + raw compressed bytes instead
  • New literal for the empty array. This didn't exist before (saves 1 byte)
  • New byte indicating the string literal stdClass - saves at least 1 byte per use.
  • A new data type for serializing packed arrays (There is a binary flag in zend_array indicating whether or not the array is packed).
    A packed array has ordered,increasing, non-negative keys (possibly with gaps)
    This saves us from serializing the keys. Add a special byte indicating a gap (or multiple gaps) in a packed array.
    (Note that a packed array may become a regular array while unserializing due to unserialize() or __wakeup())
    EDIT: and a way to detect/recover if a packed array changes to a regular array while serializing data (__sleep(), __serialize() execute code)?
  • New data type for strings that can be represented as casts from 64-bit integers (e.g. "-63212" can be represented as a 16-bit negative unsigned long (3 byte representation) instead of a 6-character string (8-byte representation)
  • EDIT: 1-byte (instead of 2-byte) encodings of common, small 8-bit integers, such as 0, 1, 2, 3, 4, ... 7
  • EDIT: New data type for single-character strings
  • EDIT: New type for lists that don't contain objects or references (recursively enforced)

EDIT: also, while making incompatible changes:

  • (bug fix) Allow multiple reference groups to the same objects... currently, at most one group is allowed by the format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions