Victor Piryns (pivi) 4892b879e6 [PERF] mail: speed up partner suggestion in chatter/discuss
Issue:
Typing '@' in a chatter and waiting for the partner suggestions can
sometimes be really slow for some users, even freeze some users
browsers.

Analysis:
Since 12152279a5 the sorting on
partner suggestions has been generalized to take an arbitrary amount
of functions to apply sequential filtering. One particular of those
is `partnerCompareRegistry['discuss.recent-chats']` which makes a
call to `getRecentChatPartnerIds` which makes multiple checks for
each pair of partners in the thread to order them based on their
`lastInterestDateTime`. This property is actually quite heavy, as it
involves deserializing datetime objects and making calls to libs and
regex matches, creating a lot of garbage memory in the process.
The complexity of this machinery is atrocious:
- First `sortPartnerSuggestions` loops over all the current partners
  we fetched from the backend, and in a `sort` callback we call
  *each* filtering method (we shortcut on the first filtering that
  succeed). So we call at worse each filter `O(n*log(n))` times.
- Since `partnerCompareRegistry['discuss.recent-chats']` is the
  lowest sequence in the filtering array, we will *always* go
  through it for those partners `O(n*log(n))` times, inherently calling
  `getRecentChatPartnerIds`.
- This function in question gets it's list of partner from the
  thread in the store, and sorts those partners with a callback
  again. So again we have `O(m*log(m))` callbacks. This callback makes
  8 calls to `lastInterestDateTime`, which as mentioned previously
  is actually an expensive function if called frequently as it
  generates a lot of garbage.
- All this garbage that is generated triggers multiple calls to the
  browser GC, and it's being frequently called, either stalling the
  browser for a few seconds, and for some users (as the problems
  scales over quadratic for the number of partners in the
  suggestions/thread) completely halting it.

Solution:
- Correct implementation of `getRecentChatPartnerIds` to not call
  `lastInterestDateTime` so frequently, it was unnecessary.
- Dependency inject the call to `getRecentChatPartnerIds` outside of
  the initial sorting callback, as it's independent of the sorting
  parameter and can be hoisted outside of the routine and injected
  into the filter.

Reference:
task-3556235

closes odoo/odoo#138988

X-original-commit: ba31d252c0738811cfe80a70bbbd7d489a45cf03
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
2023-10-18 13:39:13 +00:00
2023-10-16 13:11:17 +00:00
…
…
…
…
…

Build Status Tech Doc Help Nightly Builds

Odoo

Odoo is a suite of web based open source business apps.

The main Odoo Apps include an Open Source CRM, Website Builder, eCommerce, Warehouse Management, Project Management, Billing & Accounting, Point of Sale, Human Resources, Marketing, Manufacturing, ...

Odoo Apps can be used as stand-alone applications, but they also integrate seamlessly so you get a full-featured Open Source ERP when you install several Apps.

Getting started with Odoo

For a standard installation please follow the Setup instructions from the documentation.

To learn the software, we recommend the Odoo eLearning, or Scale-up, the business game. Developers can start with the developer tutorials

S
Description
No description provided
Readme LGPL-3.0
3.4 GiB
Languages
Python 49.6%
JavaScript 47.8%
SCSS 2%
CSS 0.3%
HTML 0.2%