Alex Vanderbist @alexvanderbist.com · Apr 23

Then there's the decoding state. Each line stored its state as an associative array and those string keys aren't free. PHP keeps them in a hashtable at ±250 bytes per entry. Swapping to just values [0,0,0,0] is only ±150 bytes per entry. A 10MB improvement on 110K lines.

0 likes 1 replies

?

Replies

Alex Vanderbist · Apr 23

The biggest win: PHP's lesser-known (un)pack function lets you store data as raw bytes instead of PHP objects. Each mapping is 5 ints. As an object that's ±200 bytes, but as 5 int32s in a packed string it's only 20 bytes. That's 10x less memory used!