Odoo Help


Performance in Environment.field_todo and iteration over self.all very slow - can it be done better?

Yurdik Cervantes Mendoza
on 3/21/16, 1:08 PM 631 views

We have noted that this method is extremely expensive in terms of performance:


Specifically during the re-computation of stored function fields:


    def recompute(self):
        """ Recompute stored function fields. The fields and records to
            recompute have been determined by method :meth:`modified`.
        while self.env.has_todo():
            field, recs = self.env.get_todo()
            # evaluate the fields to recompute, and save them to database
            names = [
                for f in field.computed_fields
                if f.store and self.env.field_todo(f)
            for rec in recs:
                    values = rec._convert_to_write({
                        name: rec[name] for name in names
                    with rec.env.norecompute():
                except MissingError:
            # mark the computed fields as done
            map(recs._recompute_done, field.computed_fields)


    def field_todo(self, field):
        """ Check whether ``field`` must be recomputed, and returns a recordset
            with all records to recompute for ``field``.
        if field in self.all.todo:
            return reduce(operator.or_, self.all.todo[field])

Is that really the fastest way? 

Richard Möhn
On 4/1/16, 5:39 AM

I can't comment, so I'll  have to answer the question that's written below here.

That error occurs, because they're iterating over `Environment.all`, which ultimately means iterating over a `WeakSet`, and there was some Python bug in `WeakSet`s that caused the error.

`Environment.all.todo`, however, is an ordinary dictionary with lists as values, so there shouldn't be a problem.

I see that you have proposed a fix: https://github.com/OCA/OCB/pull/460 Thank you.

Yurdik Cervantes Mendoza
on 4/1/16, 6:48 AM

Does the self.all.todo iteration need to be protected the same way that the iteration of self.all  ?  (http://bit.ly/1RfxsL1)


RuntimeError: Set changed size during iteration

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 3/21/16, 1:08 PM
Seen: 631 times
Last updated: 4/1/16, 6:49 AM