Skip to content

Improve performance of issue trigger identification #6493

@sebastianbergmann

Description

@sebastianbergmann

Context

When PHPUnit handles deprecation warnings during test execution, the ErrorHandler uses SourceFilter::includes() to determine whether the deprecation was triggered in first-party code or third-party code (self, direct, or indirect).

As reported in #6111 and #6469, for example, some users are experience a significant performance degradation since issue trigger identification was introduced.

SourceMapper::map() is slow

SourceFilter::includes() uses a map that is generated by SourceMapper::map(). The latter scans the configured <source> directories to build a list of first-party files.

This file scanning operation can cause significant performance degradation, especially when:

  • The <source> include/exclude patterns are overly broad
  • The configured source directories contain many files
  • Many deprecation warnings are triggered during a test run

SourceMapper::map() is called multiple times when process isolation is used

SourceMapper::map() is called only once per PHPUnit process. However, when tests are run in separate processes (--process-isolation CLI option, processIsolation="true" XML configuration file setting, or #[RunInSeparateProcess] and #[RunTestsInSeparateProcesses] attributes) then SourceMapper::map() performs the potentially expensive file scanning operation multiple times, once in the parent process and once in each child process.

Plan

Metadata

Metadata

Labels

feature/issuesIssues related to handling of `E_*` emitted by the PHP runtime and `E_USER_*` emitted in PHP codetype/performanceIssues related to resource consumption (time and memory)version/11Something affects PHPUnit 11version/12Something affects PHPUnit 12version/13Something affects PHPUnit 13

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions