Issue Bug Closed

#106822LanguagePackService::getExtensionLanguagePackDetails() causes major performance issues due to Finder usage and file counting

Kerem Koc 06/04/25, 12:05 updated 08/11/26, 08:46

Description

In TYPO3 v12.4, we’ve identified a serious performance bottleneck in the method LanguagePackService::getExtensionLanguagePackDetails()

💥 Problem:

The current implementation performs expensive and repeated filesystem scans using Symfony’s Finder component. Specifically:
1. Unnecessary file counting

$files = $finder->files()->in($path . 'Resources/Private/Language/')->name('*.xlf');
if ($files->count() === 0) {
    continue;
}

$files->count() iterates through all matching files just to check if there’s at least one.

This results in tens of thousands of unnecessary file operations when only a boolean check is needed.

✅ Suggestion: Replace with hasResults() (available since Symfony Finder 3.4):

if (!$files->hasResults()) {
    continue;
}

2. Repeated Finder instantiation and recursion

    The Symfony Finder is instantiated and executed once per extension.

    With each call, RecursiveDirectoryIterator and related filesystem iterators are invoked.

    In our profiling, this led to 134,000+ calls to RecursiveDirectoryIterator::current() across requests.

    This is amplified when 20+ languages are configured in EXTCONF['lang']['availableLanguages'].
$packageManager = GeneralUtility::makeInstance(PackageManager::class);
$activePackages = $packageManager->getActivePackages();
foreach ($activePackages as $package) {
    $finder = new Finder();
    $files = $finder->files()->in($path . 'Resources/Private/Language/')->name('*.xlf');
}

📉 Result: Extremely high I/O and CPU cost even for extensions with no translation files.
🧪 Our setup (example):

'EXTCONF' => [
    'lang' => [
        'availableLanguages' => [
            'ar', 'bg', 'cs', 'de', 'es', 'fr', 'hu', 'it', 'ja', 'ko',
            'lt', 'nl', 'pl', 'pt', 'pt_BR', 'ro', 'ru', 'sk', 'tr',
            'uk', 'vi', 'zh', 'zh_HK',
        ],
    ],
],

📊 Observed impact:

Over 120,000 Finder iterations during a single languagePackDownload() cycle.
134,000+ calls to RecursiveDirectoryIterator::current() (measured via profiling tools).
Significant performance degradation during Extension Manager operations, language pack processing, and installs.

Recommendation:

Replace $files->count() === 0 with !$files->hasResults()
Avoid creating a new Finder instance per package — consider memorization or shared reuse if feasible

Reviews 4

History 411

  1. Stephan Großberndt changed description 07/29/25, 09:06

  2. Stephan Großberndt commented 07/29/25, 10:27

    - Using only one Finder instance makes the performance much worse
    - Using !$files->hasResults() improves the performance slightly
    - the actual problem which leads to so many file IO is a different one. There are a huge amount of unneeded calls to getExtensionLanguagePackDetails() which iterates ALL extensions:

    77485: [FEATURE] Introduce event to prevent downloading of language packs introduced a “hack”:

        public function languagePackDownload(string $key, string $iso): string
    
    ...
    
            // Kinda hacky, but we need this as the install tool requests every language for every extension
            $extensions = $this->getExtensionLanguagePackDetails();
            if (!isset($extensions[$key]['packs'][$iso])) {
                return 'skipped';
            }

    languagePackDownload is called from LanguagePackCommand for each extension for each language. Each of these calls leads to another call of getExtensionLanguagePackDetails() fetching all extensions all over again only to check the event. This is completely unnecessary here as the LanguagePackCommand did already fetch getExtensionLanguagePackDetails() as a base on which extensions to operate.

    The reason this hack was introduced here is the call of languagePackDownload() from MaintenanceController->languagePacksUpdatePackAction() where any extension key or iso could be sent in a request.

    The hack should be removed from languagePackDownload.

  3. Gerrit Code Review pushed patch set 1 for main to change 92822 status New Under Review 02/12/26, 13:48

  4. Gerrit Code Review pushed patch set 1 for main to change 93785 04/21/26, 15:07

  5. Gerrit Code Review pushed patch set 2 for main to change 93785 04/22/26, 07:21

  6. Gerrit Code Review pushed patch set 3 for main to change 93785 05/04/26, 19:12

  7. Gerrit Code Review pushed patch set 4 for main to change 93785 05/04/26, 21:14

  8. Gerrit Code Review pushed patch set 5 for main to change 93785 05/04/26, 21:15

  9. Gerrit Code Review pushed patch set 1 for 14.3 to change 94337 06/05/26, 11:40

  10. Benni Mack commented and changed status Under Review Resolved done 0 % 100 % 06/05/26, 11:55

    Applied in changeset commit:7506b1027c65ad6ef9a264a8382a0b456dbed2d1.

  11. Benni Mack changed status Resolved Closed 08/11/26, 08:46