Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Cache DcaExtractor result #7324

Closed
Toflar opened this issue Sep 17, 2014 · 4 comments
Closed

Cache DcaExtractor result #7324

Toflar opened this issue Sep 17, 2014 · 4 comments
Labels
Milestone

Comments

@Toflar
Copy link
Member

Toflar commented Sep 17, 2014

I discovered a huge performance issue with the DcaExtractor while doing some performance analysis for Isotope with xdebug. Contao calls $objDca = new \DcaExtractor(static::$strTable); every single time a model is created (see Model::__construct()). In my case I had 1300 model instances which results in 1300 instances of DcaExtractor. Each and everyone including the 'system/cache/sql/' . $strTable . '.php'; and thus accessing the file system 1300 times. In fact, it would be enough to do this one time per table.

I suggest introducing a DcaExtractor::getForTable($strTable) and using this one wherever possible:

public static function getForTable($strTable)
{
    if (static::$arrInstances[$strTable] === null)
    {
        static::$arrInstances[$strTable] = new static($strTable);
    }

    return static::$arrInstances[$strTable];
}

I was able to speed up an Isotope product list generation by 6%.

@leofeyer leofeyer added this to the 3.4.0 milestone Sep 17, 2014
@leofeyer
Copy link
Member

Changed in 800ed2d. Unfortunately, I cannot protect the constructor to force people to use the getInstance() method, because it would break backwards compatibility.

@Toflar
Copy link
Member Author

Toflar commented Sep 24, 2014

I know, that's fine :)

@leofeyer
Copy link
Member

Changed it in Contao 4 though: contao/contao-library@4336580f10967f19a3ff78affe10a4c28fce7926

@leofeyer
Copy link
Member

The change log entry and update notice is here: contao/contao@94ed57e

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants