Skip to content

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Feb 3, 2026

closes phpstan/phpstan#8636

running make tests before and after this PR results in ~30 seconds runtime on my machine, so it seems we are fast enough to allow bigger arrays


I changed the tests/PHPStan/Analyser/data/bug-5081.php test to accomodate 1 element more as we allow.
all other tests have just been adjusted to reflect the new reality.

tests/PHPStan/Rules/Methods/data/bug-8636.php reported Method Config::huge() should return string but returns array<int, string>|string. before this PR and does not longer after this PR.

@staabm
Copy link
Contributor Author

staabm commented Feb 3, 2026

//cc @gnutix please try the .phar file from the build artifacts of this PR and check it on your problematic codebase from phpstan/phpstan#8636

@staabm staabm marked this pull request as ready for review February 3, 2026 16:02
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

Copy link
Contributor

@VincentLanglet VincentLanglet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like phpstan/phpstan#8636 (comment) would be a great way to solve such issue rather than updating the limit for every projects

];
}

assertType('int<0, max>', count($alerts));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of those tests were about oversizedArray.
Like this one phpstan/phpstan#11703 reporting an oversized array was considered as always non-empty.

With this "test update", the regression is not covered anymore since we are not testing oversizedArray anymore but just big constantArray.

If you change ARRAY_COUNT_LIMIT, IMHO all the oversized array in the tests need to be updated to stay oversized array.
Which is some works...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I should adjust that some tests still use the 256 limit

Copy link
Contributor

@VincentLanglet VincentLanglet Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I should adjust that some tests still use the 256 limit

That could be a great way indeed ;

And if the limit is configurable for tests (only cf #4856 (comment) indeed) it could give us easier test writing of oversize array by lowering the limit when needed (?)

@staabm
Copy link
Contributor Author

staabm commented Feb 4, 2026

I feel like phpstan/phpstan#8636 (comment) would be a great way to solve such issue rather than updating the limit for every projects

see #4850 (comment)

$container->getService('typeSpecifier');

BleedingEdgeToggle::setBleedingEdge($container->getParameter('featureToggles')['bleedingEdge']);
ConstantArrayTypeBuilder::setArrayCountLimit(256);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be the opposite ?
Letting 512 as default, and manually calling setArrayCountLimit(256) for test which need it ?

Maybe it's because I'm not familiar with this code but setting 256 in postInitializeContainer won't also set it for user of phpstan (and not only for tests) ?

@staabm
Copy link
Contributor Author

staabm commented Feb 4, 2026

tried a few different things but was not yet successful to make the setting have a different value for certain test cases, as I don't want to introduce a new container parameter (which would allow people to define the setting at app level).

@staabm staabm marked this pull request as draft February 4, 2026 13:32
@gnutix
Copy link
Contributor

gnutix commented Feb 4, 2026

I ran benchmarks on our codebase (~4min total PHPStan runtime) by patching the ARRAY_COUNT_LIMIT constant directly in the 2.1.38 PHAR. Cold cache for each run.

Limit phpstan-main phpstan-legacy Total
256 (current) 127.93s 112.90s 240.83s
512 (this PR) 141.98s 99.42s 241.40s
1024 (because why not) 126.47s 99.38s 225.85s

Single run each (no iterations), so variance across rows is just noise. The totals are essentially identical — no measurable performance impact from doubling or even quadrupling the limit on this codebase.

Given that there's no performance regression (or at least measurable on this codebase, I know), would it make sense to remove the limit entirely? or make it a configurable parameter? I can't say I understand the strategy of "just doubling it", it feels arbitrary if we can't measure differences in benchmarks.

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.

Oversimplified huge const array

4 participants