Skip to content

Code Optimizations (Memory Usage) #40

@Zanaras

Description

@Zanaras

Broadly speaking, there's not much point to over optimizing PHP as it's a just-in-time compiler that uses resources briefly to generate pages, except when it comes to the turn scripts. These scripts are run on the command line which means they're not subject to execution or memory limits as much as those ran through the web browser.

PHP itself will start to struggle when it's handling too many objects in memory, which is why a lot of the bulk processing is done through iterators. $doctrine->clear() is good for releasing a lot of stuff, but there's still a lot of left over variables that are never used again that we could clear up as well.

https://stackoverflow.com/questions/584960/whats-better-at-freeing-memory-with-php-unset-or-var-null has a good discussion on this but it boils down to:

$var = null;
unset($var);

This reduces the memory allocation then flags it cleanup. Don't use this inside loops though, as you're adding a bunch of extra memory work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions