Caching ir.model.data records in convert?

I run “trytond-admin --all” using vmprof and a quick look seems to indicate that around 40% of the time is spent on convert.py’s fetch_new_module().

This method caches all the ir.model.data information of a module when another module references at least one of its records.

For example, say that a module wants to add a menu item which has the “Products” menu item as parent. Then, fetch_new_module will ensure all ir.model.data identifiers of the “product” module are loaded.

The problem seems to be that when I run --all, if I have both “product_measurements” and “product_price_list”, fetch_new_module() willl be called twice (and loaded twice) because the information loaded on the update of “product_measurements” is not reused when “product_price_list” is updated.

Before trying to go any deeper, as I don’t have an in-depth knowledge of this process and its implications I was thinking: would it be doable to cache this information? What side effects could it have?

One possible problem I undestand that there may be is if some __register__ method updates ir.model.data table directly, but we could allow some kind of invalidation in that case.

40% seems like a huge percentage, not to try to reduce it somehow.

We can not reuse the instance from one module parser to another because potentially the class of the Model maybe different.
For me, the more expensive task in fetch_new_module is the validation of the id ('id', 'in', list()) but it is needed to avoid AccessError when prefetching data.

Maybe we can apply something similar to: Issue 7196: Improve common XML search - Tryton issue tracker

I do not understand the proposal. The result of the search is an id so it is static. How does it applies to a record instance?

A record instance is the result of a search, so if we can cache the id we can also cache the record instance. Don’t we?

I do not understand your proposal. What, how long and how do you want to cache record?

I have nothing concrete, just found the issue and I thought that may be relevant for this thread. Then I posted here if someone wants to dig more in the case.