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.
Memory growth in long-running CLI commands caused by SearchExecutionService debug trace collection
Summary
SearchExecutionServicestores every executed query in an in-memory array ($executedSearches), including full response payload anddebug_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.phpWhy this is problematic
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.