-
Notifications
You must be signed in to change notification settings - Fork 23.2k
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
[IMP] core: remove useless mapped call when calling filtered with a str #105350
[IMP] core: remove useless mapped call when calling filtered with a str #105350
Conversation
The mapped call is supposed to populate the cache, but that's already taking care of by prefetching. It ends up adding an overhead instead. The perf improvement is more noticeable on large recordsets. For example, on a database populated with 100k res.partner records. Before: .. code-block:: python partners = env["res.partner"].search([]) partners.filtered("name") # warm up timeit.timeit(lambda: partners.filtered("name"), number=10) # result: 7.15 After: .. code-block:: python partners = env["res.partner"].search([]) partners.filtered("name") # warm up timeit.timeit(lambda: partners.filtered("name"), number=10) # result: 4.67
Thanks for the proposal, but we need some deeper analysis. I mean that your analysis in the description above is flawed. The code that you remove is responsible for "warming up" the cache efficiently. If the cache is already "warm", the code is by definition useless, and removing it obviously makes @ryv-odoo is going to check this. |
Thank you both, In my example I wanted to show that Before: partners = env["res.partner"].search([])
timeit.timeit(lambda: partners.filtered("name") and partners.env.cache.clear(), number=100)
# result: 495.05 After: partners = env["res.partner"].search([])
timeit.timeit(lambda: partners.filtered("name") and partners.env.cache.clear(), number=100)
# result: 281.33 My reasoning is that the cache doesn't need warming up. There's no real gain in perf, because otherwise the prefetching will just work, and do a good job at it. |
Hello @ivantodorovich , Thank you It seems very interesting but your numbers seems over optimistic. What is your computer set up (python version, etc) ? On my computer: (2700 partners) |
My previous comment is not complete and I found why we don't have the same result. There is complexity issue with In my opinion we should fix |
Hello @ryv-odoo , I'm running these snippets on a db with roughly 100k partners. So yeah, plenty more than yours if there's something to improve in mapped, it will definitely have a bigger impact. But anwyay, I still think this mapped call on |
Hello,
Yes it is correct. The I verified with others parameters/models (filtered with complex relational path by example) to ensure that it is always more efficient. And the conclusion is the same than yours. @robodoo r+ Thank you @ivantodorovich The mapped issue will be addressed later. |
The mapped call is supposed to populate the cache, but that's already taking care of by prefetching. It ends up adding an overhead instead. The perf improvement is more noticeable on large recordsets. For example, on a database populated with 100k res.partner records. Before: .. code-block:: python partners = env["res.partner"].search([]) partners.filtered("name") # warm up timeit.timeit(lambda: partners.filtered("name"), number=10) # result: 7.15 After: .. code-block:: python partners = env["res.partner"].search([]) partners.filtered("name") # warm up timeit.timeit(lambda: partners.filtered("name"), number=10) # result: 4.67 closes #105350 Signed-off-by: Rémy Voet <ryv@odoo.com>
The mapped call is supposed to populate the cache, but that's already taking care of by prefetching.
It ends up adding an overhead instead.
The perf improvement is more noticeable on large recordsets.
For example, on a database populated with 100k res.partner records.
Before:
After:
Although the perf imp is miniscule in real world cases, these lines can be misleading IMO.
I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr