Tech article

I Added One Key to a PHP Array. It Cost 25 MB of Memory

Community description: I was recently refactoring some legacy PHP code and noticed that the same data array was being used...

Dev.to | Sep 14, 2026 | Nazar Boyko

Automated excerpt

One counts up and the other counts down. packed list, keys 0.. N-1 in order 16,781,392 bytes 16. 78 bytes/elem range(0, N-1) 16,781,392 bytes 16. 78 bytes/elem same keys, filled in reverse order 41,943,120 bytes 41. 94 bytes/elem SplFixedArray of N ints 16,003,192 bytes 16. 00 bytes/elem Two and a half times the memory for the same million integers, because I filled it backwards. Take the packed million and give it one string key. A million integers cost 16. 00 bytes per element exactly against the packed array's 16.

Selected automatically from source text; not independently written or fact-checked. Read the original for full context.

Read the original article

More tech news