Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration for maximum size of shaped array #7433

Merged
merged 3 commits into from Mar 15, 2022

Conversation

danog
Copy link
Collaborator

@danog danog commented Jan 19, 2022

No description provided.

@orklah
Copy link
Collaborator

orklah commented Jan 19, 2022

Sorry, but I don't like this

This kind of limits are frequently calibrated to prevent runaway processing that leads to memory issues, performance issues and prevent stability issues in general.

It adds complexity in Psalm and will probably be missused by most users and they'll end up ticketing here bugs that will be pretty hard to find.

What is your actual use case for this?

@danog
Copy link
Collaborator Author

danog commented Jan 19, 2022

My actual usecase involves completely disabling this check in my fork, I used this at work to automatically typecheck mongoDB queries (including up to 3-level nested $or, $and, $eq, $gt, $gte, $in, $lt, $lte, $ne, $nen syntax :D).

The typechecks worked perfectly, but caused 30-minute psalm scans with up to 20GB of RAM, and were promptly disabled :D

Still, I kept the checks disabled, as I imagine they can slightly improve overall type inferring, and that's also the reason why I submitted this MR.

@orklah
Copy link
Collaborator

orklah commented Jan 19, 2022

Ok, I get it, I thought you wanted to go the other way (to have more literals). Well, I have mixed feelings on that.

On one hand, I know there are some issues not fixed yet where not having literals in an array created false positives, so this is not just a neutral feature we can just disable. On the other hand, if there are dramatic perf improvements, it would be a shame not to be able to have them when needed...

@danog
Copy link
Collaborator Author

danog commented Jan 19, 2022

I thought you wanted to go the other way (to have more literals)

Actually, that's exactly what I wanted to do, I wanted to set a huge limit like PHP_INT_MAX :D

@orklah
Copy link
Collaborator

orklah commented Jan 19, 2022

You'll hit hard walls at some point. If you try to use a switch on that, I believe the wall will be very big and with spikes too.

The issue is that Psalm checks can be exponential. Luckily, Psalm is pretty quick, but no matter how quick, there is one point where the exponential process will takes years to complete. And it's waaay before PHP_INT_MAX 😄

@danog
Copy link
Collaborator Author

danog commented Jan 19, 2022

The issue is that Psalm checks can be exponential

Does this mean we can use a SAT solver to run psalm now? :D

@danog
Copy link
Collaborator Author

danog commented Jan 26, 2022

Btw, at work we run psalm with this config @ PHP_INT_MAX, and (single-threaded, uncached) scans complete in just 5 minutes with 420k lines of code, ~4.7 million lines considering dependencies :)

@AndrolGenhald
Copy link
Collaborator

@orklah How would you feel about this if documentation were added that warned about potential memory/runtime issues? I've sometimes wanted to increase other limits like this, and it would be nice to be able to do, as long as the documentation makes it very clear that you're playing with fire by increasing it.

@orklah
Copy link
Collaborator

orklah commented Jan 26, 2022

Configs like that

  • are easy to add
  • may create weird bugs that will be hard to reproduce
  • will be used only by a handful of users
  • will add complexity
  • are very hard to get rid off once we don't need them anymore

I guess I just don't see the point. Once this one is included, I can think of a handful more exactly like that at different places in Psalm, we won't add config for each and every one...
Just the last two weeks we added or were suggested to add at least 5 different new configs, this is not a healthy pace and even I can't say that I know what every config we have does.

Maybe we should have a much more powerful config tool if we want to consider going at this level of details. I'm thinking of something like about:config in firefox where a lot of configs are available but you have to be sure of what you do before changing one.

Maybe something that wouldn't depend on the xsd to add or remove configs...

That way we could keep important configs in a visible place and the rest would be available for power users but almost invisible for the rest?

You have thoughts on that @weirdan?

@danog
Copy link
Collaborator Author

danog commented Jan 26, 2022

Once this one is included, I can think of a handful more exactly like that

Actually, I added it exactly after another (undocumented) similar config, maxStringLength :D

I also didn't document it in a similar manner to maxStringLength: I assumed that the latter was a somewhat internal config, and followed the same approach with this one.

@AndrolGenhald
Copy link
Collaborator

AndrolGenhald commented Jan 26, 2022

I guess I just don't see the point. Once this one is included, I can think of a handful more exactly like that at different places in Psalm, we won't add config for each and every one... Just the last two weeks we added or were suggested to add at least 5 different new configs, this is not a healthy pace and even I can't say that I know what every config we have does.

True, there are a lot of config options available, and more being added.

That way we could keep important configs in a visible place and the rest would be available for power users but almost invisible for the rest?

What do you think about not using attributes on the root element, but on some child element? Something like:

<psalm
    [a bunch of config attributes]
>
    <RuntimeLimits
        maxStringLength="100"
        maxShapedArraySize="100"
    />
</psalm>

That way they'd be grouped separately from the rest of the options.

@orklah
Copy link
Collaborator

orklah commented Jan 26, 2022

Grouping them is a good idea!

I wonder if getting them out of the xml could be interesting. I find the XSD validation to be perfect for issuesHandler because we can autocomplete and validate the user input. However, for simple key/values for configs, I find it pretty heavy. Also the current handling in Config that force us to have a new property for each config is really heavy and create unnecessary BC breaks when we want to remove some.

For complex config, maybe a simple json would be enough and stored as an array in some kind of ConfigValue object?

Just throwing ideas here :p

@weirdan
Copy link
Collaborator

weirdan commented Jan 26, 2022

You have thoughts on that @weirdan?

I kinda like what they did in this regard in roave/backward-compatibility-check: Roave/BackwardCompatibilityCheck#377.

With that said, there's nothing wrong with using your own fork of Psalm either.

@danog
Copy link
Collaborator Author

danog commented Mar 14, 2022

Can I haz merge||definitive close :3
This is really just a counterpart for maxStringLength: if that config key already exists, I don't see why shouldn't this one exist, either...

@orklah orklah added release:feature The PR will be included in 'Features' section of the release notes and removed PR: Need review labels Mar 14, 2022
@orklah
Copy link
Collaborator

orklah commented Mar 14, 2022

Can you add some documentation on this config? Please add a note about how changing this to low or high values could have unintended effects and that those side effects won't be considered as bugs.

@danog
Copy link
Collaborator Author

danog commented Mar 15, 2022

Done!

@orklah
Copy link
Collaborator

orklah commented Mar 15, 2022

Thanks!

@orklah orklah merged commit ebffd52 into vimeo:4.x Mar 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:feature The PR will be included in 'Features' section of the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants