Skip to content

Memory growth in long-running CLI commands #417

Description

@simon-matt-oetztal

Memory growth in long-running CLI commands caused by SearchExecutionService debug trace collection

Summary

SearchExecutionService stores every executed query in an in-memory array ($executedSearches), including full response payload and debug_backtrace() for each search.

In long-running CLI processes (e.g. reindex/import/update loops), this leads to continuous memory growth even when debug output is not used.

Affected code

src/SearchIndexAdapter/DefaultSearch/Search/SearchExecutionService.php

$this->executedSearches[] = new SearchInformation(
    $search,
    true,
    $defaultSearchResult,
    $executionTime,
    debug_backtrace(),
);

Why this is problematic

  • debug_backtrace() is expensive and large.
  • The array is process-wide and accumulates over many searches.
  • In production CLI contexts, this debug information is typically never consumed.
  • executedSearches is primarily used by DebugSubscriber (response debug endpoint).

Expected behavior

Debug query history should only be collected when debug mode is active.

Proposed fix

Guard writes to $executedSearches with debug mode check, e.g. Pimcore::inDebugMode().

This keeps current debug functionality in dev/debug, while preventing avoidable memory retention in prod/no-debug CLI workloads.

Metadata

Metadata

Assignees

Type

No type

Fields

Affected capability

None yet

Platform Version

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions