maximebf / php-debugbar

Debug bar for PHP
phpdebugbar.com
MIT License
4.2k stars 402 forks source link

Exponential memory usage growth with stacked data and Request collector #665

Open dotdash opened 2 months ago

dotdash commented 2 months ago

The request data collector store the data from $_SESSION which contains the stacked data, which in turn contains the data from the request collector, etc, so memory usage double with each request. So with multiple requests that have a request data collector and getting stacked, that becomes a problem rather quickly.

dotdash commented 2 months ago

FWIW, I have created a derived class locally, that simply drops the stacked data from the session whenever collecting data:

    /**
     * @return mixed[]
     */
    public function collect(): array
    {
        $http = $this->initStackSession();

        // Avoid quadratic memory usage growth by removing any stacked data
        // from the session, as the stacked data may also contains the session
        $stack = $http->getSessionValue($this->stackSessionNamespace);
        $http->deleteSessionValue($this->stackSessionNamespace);

        $data = parent::collect();

        $stack = $http->setSessionValue($this->stackSessionNamespace, $stack);

        return $data;
    }
parallels999 commented 2 months ago

Open a pull request 👍