I'm having quite a bit of fun working on PXP again.
My task for this evening was tracking down ways of reducing memory consumption when indexing large PHP projects.
Indexing the entirety of the `laravel/framework` repo (incl. vendor) went from using 7GB to 2.7GB. I'd call that a win!
My task for this evening was tracking down ways of reducing memory consumption when indexing large PHP projects.
Indexing the entirety of the `laravel/framework` repo (incl. vendor) went from using 7GB to 2.7GB. I'd call that a win!
Comments
These are the sort of things that held me back from progressing before. Random OOM errors destroying my laptop, so it's nice to do some tidy-up work. Set myself up for success 💪
The amount of memory used when allocating an enum in Rust is based on the largest variant, so if you've got a 24 byte variant and a 700 byte variant, no matter which variant you're creating it will always allocate 700 bytes.
Some of these nodes are large and hold lots of data, but even if I only wanted to allocate a simple BoolExpression, it would allocate 2kB of memory because of larger expressions such as Closure and AnonymousClass.
The solution was to just wrap these fields in a Box. They'll be stored on the heap, rather than the stack, but it means that the enum itself will only ever allocate 32 bytes.
It does sound like a load of gobbledygook, but I assure you the words do mean something!