-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Remove lru_cache
from get_message_definitions
#5673
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
Conversation
Pull Request Test Coverage Report for Build 1692882877
π - Coveralls |
Are you sure that caching 'self' is an issue ? Messages stores are singletons. 0,01s for each pylint startup is significant imo. (Well it should be, and it will once astroid's import is faster). |
I'm not sure whether this creates any real trouble immediately, but I think it would be good to enforce I did a quick test for running Same test with I don't think this will be the first function that needs performance optimisation π |
We never change the content of the cache and the value for a given pylint version are always the same. Also there is always only one instance. As we said in the original MR the RAM used is negligible and deterministic. I don't see how it could become a problem. For multiprocessing the cache is not shared but actually generated for each thread see this comment. (It makes me want to generate the message store code into an optimized data structure. It would remove the checks for consistency at each initialization, we can do it once for each release instead of doing it once for each time pylint is used. This is #5607 .) |
Don't plugin messages get registered on the
You're right but I'd think I'd prefer to follow our new message here rather than adding a disable for it. The impact of this optimisations would be minimal: For me that warrants readability/maintainability over performance. Not adding the |
Yes it's discussed in #5607, we can't just remove the code doing the check entirely.
I agree there's more pressing optimization to do, and this function scale with run time (contrary to other optimization that have a fixed cost that we pay each time pylint is launched). But pylint is also downloaded 250 000 time a day, used maybe 10 time for each download, if we take into account an average use time of 10s, it adds up to more than an hour saved each day if we just disable this one false positive that we know will lower performance ever so slightly. We also have worst complexity to care about, the disable + short explanation won't be what make pylint unmaintainable imo π |
I'll give in. I'll add a disable in #5674 and close this. π Do you have any good ideas on how to allow this behaviour without adding a |
I think singleton should be exempted, but I don't think there is a consensus on a pattern to indicate that an instance is a singleton in python. (See https://stackoverflow.com/questions/6760685/creating-a-singleton-in-python) |
Type of Changes
Description
Ref #5670, #5605
This cache isn't actually that necessary. As long as
message_id_store.get_active_msgids
is reasonably fast (or cached) this function is also quite fast.I tested using a similar pattern as in #5672 but actually setting values to a
dict
instance attribute and retrieving them takes longer than just doing the list comprehension for the return values ofget_active_msgids
. I think this is because ifget_active_msgids
returns just onemsgid
it's just one dict lookup whereas with a primitive cache it would be one dict lookup but also one dict assignment.Anyway, a cache seems over engineered looking at the changes in these run times as long as
get_active_msgids
is cached.Tested on
pylint
overpylint
.With lru_cache:
With new cache:
Without new cache:
Problem introduced in #5605