Skip to content

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Aug 29, 2025

testing with https://github.com/staabm/php-code-coverage-bug1062 reveleaed:

before 6afb0db we fatal errored

➜  php-code-coverage-bug1062 git:(main) vendor/bin/phpunit --coverage-text --only-summary-for-coverage-text tests/Test.php
PHPUnit 12.3.7 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.24 with Xdebug 3.4.5
Configuration: /Users/staabm/workspace/php-code-coverage-bug1062/phpunit.dist.xml

MobileServiceApi2018093110807480PHP Fatal error:  Allowed memory size of 3439329280 bytes exhausted (tried to allocate 1073741832 bytes) in /Users/staabm/workspace/php-code-coverage-bug1062/vendor/phpunit/php-code-coverage/src/Target/MapBuilder.php on line 167

Fatal error: Allowed memory size of 3439329280 bytes exhausted (tried to allocate 1073741832 bytes) in /Users/staabm/workspace/php-code-coverage-bug1062/vendor/phpunit/php-code-coverage/src/Target/MapBuilder.php on line 167

since 6afb0db we de-duplicate the array contents earlier which means less memory required while working -> we ran the repro without fatal error

➜  php-code-coverage-bug1062 git:(main) vendor/bin/phpunit --coverage-text --only-summary-for-coverage-text tests/Test.php
Xdebug: [Step Debug] Could not connect to debugging client. Tried: 127.0.0.1:9003 (through xdebug.client_host/xdebug.client_port).
PHPUnit 12.3.7 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.24 with Xdebug 3.4.5
Configuration: /Users/staabm/workspace/php-code-coverage-bug1062/phpunit.dist.xml

F                                                                   1 / 1 (100%)

Time: 00:00.072, Memory: 22.00 MB
...

with this PR we prevent unnecessary work and run twice as fast as with 6afb0db

➜  php-code-coverage-bug1062 git:(main) vendor/bin/phpunit --coverage-text --only-summary-for-coverage-text tests/Test.php
Xdebug: [Step Debug] Could not connect to debugging client. Tried: 127.0.0.1:9003 (through xdebug.client_host/xdebug.client_port).
PHPUnit 12.3.7 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.24 with Xdebug 3.4.5
Configuration: /Users/staabm/workspace/php-code-coverage-bug1062/phpunit.dist.xml

F                                                                   1 / 1 (100%)

Time: 00:00.039, Memory: 22.00 MB
...

@staabm staabm marked this pull request as ready for review August 29, 2025 06:54
de-duplicate logic and re-use fast path in more places
@staabm
Copy link
Contributor Author

staabm commented Aug 29, 2025

with the last commit I think the implementation got a bit easier.
it uses the same fast-path for all cases now and renders the reproducer even faster and with even less memory:

➜  php-code-coverage-bug1062 git:(main) vendor/bin/phpunit --coverage-text --only-summary-for-coverage-text tests/Test.php
Xdebug: [Step Debug] Could not connect to debugging client. Tried: 127.0.0.1:9003 (through xdebug.client_host/xdebug.client_port).
PHPUnit 12.3.7 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.24 with Xdebug 3.4.5
Configuration: /Users/staabm/workspace/php-code-coverage-bug1062/phpunit.dist.xml

F                                                                   1 / 1 (100%)

Time: 00:00.032, Memory: 18.00 MB
...

@sebastianbergmann sebastianbergmann merged commit 52e5f81 into sebastianbergmann:main Aug 29, 2025
16 checks passed
@staabm staabm deleted the fast branch August 29, 2025 10:31
@sebastianbergmann sebastianbergmann changed the title Faster MapBuilder->build() Faster MapBuilder::build() Aug 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants