Hi Sandy,

wt., 6 lut 2024 o 21:19 Sanford Whiteman <figureone...@gmail.com>
napisał(a):

> Howdy all, haven't posted in ages but good to see the list going strong.
>
> I'd like a little background on something we've long accepted: why
> does the serialization format need double quotes around a string, even
> though the byte length is explicit?
>
> Example:
>
>   s:5:"hello";
>
> All else being equal I would think we could have just
>
>   s:5:hello;
>
> and skip forward 5 bytes. Instead we need to be aware of the leading
> and trailing " in our state machine but I'm not sure what the
> advantage is.
>

You inspired me to play with serialization format to spot even more
unnecessary chars https://3v4l.org/DLh1U
>From my PoV there are more candidates to reduce and still keep the safety,
for eg:
removing leading ':' before array/object and trailing ';' inside brackets,
you reduce by 2 bytes

a:4:{i:0;i:123;i:1;b:1;i:2;d:1.1;i:3;s:3:"baz";}

Could be simply

a:4{i:0;i:123;i:1;b:1;i:2;d:1.1;i:3;s:3:baz}

This example saves 4 bytes: double-quotes, one ; and :

If you go further all types that require size/length also don't need extra
double-colon meaning:
a:4 could become a4
s:3 could become s3

The same could apply to O: and E:

O3:Foo:5{s4:date;O17:DateTimeImmutable:3{s4:date;s26:2024-02-08
08:41:10.009742;s13:timezone_type;i:3;s8:timezone;s16:Europe/Amsterdam}s6:*foo;s11:Foo
bar
baz;s8:Foobar;i:123456789;s3:tbl;a4{i:0;i:123;i:1;b:1;i:2;d:1.1;i:3;s3:baz}s8:*color;E12:Color:Yellow}

This is still readable by humans and keep the size/length in all places
where needed.
My attached example is poor but shows up to ~20% size reduction.

Interestingly when an array is serialized as object property it is not
followed by ; in field list https://3v4l.org/4p6ve

O:3:"Foo":2:{s:3:"foo";a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}s:3:"bar";s:3:"baz";}

Missing ; between }s was a surprise to me.

Best regards,
Michał Marcin Brzuchalski

Reply via email to