Hello everyone, 

why this line is inside the loop?

https://github.com/odoo/odoo/blob/132c7e75e57321c77aac9250a2587c74c5da7857/addons/account/models/account_move.py#L1364

We were removing 100k~ account.move.line records for testing purposes. It took ages. So we do some little investigation and saw this, we took out from the loop the process duration became minutes from hours.

Regards from Projet
partial_rec_set[x] = None
            digits_rounding_precision = aml_set[0].company_id.currency_id.rounding
            if float_compare(total_debit, total_credit, precision_rounding=digits_rounding_precision) == 0 \
              or (currency and float_is_zero(total_amount_currency, precision_rounding=currency.rounding)):
                #if 
                exchange_rate_entries |= self.env['account.move'].search([('rate_diff_partial_rec_id', 'in', [x.id for x in partial_rec_set.keys()])])
        # re
        reversed_moves = exchange_rate_entries.reverse_moves()
        # fi
        pairs_to_rec = []
        for rev_move in self.env['account.move'].browse(reversed_moves):
            if not rev_move.rate_diff_partial_rec_id:
                continue
            origin_move = exchange_rate_entries.filtered(lambda x: x.rate_diff_partial_rec_id == rev_move.rate_diff_partial_rec_id)
            for acm_line in rev_move.line_ids:
                if acm_line.account_id.reconcile:
                    for origin_line in origin_move.line_ids:
                        if origin_line.account_id == acm_line.account_id and origin_line.debit == acm_line.credit and origin_line.credit == acm_line.debit:
                            to_unlink |= origin_line.matched_debit_ids | origin_line.matched_credit_ids
                            to_rec = origin_line + acm_line
                            pairs_to_rec.append(to_rec)
        #mak
        exchange_rate_entries.write({'rate_diff_partial_rec_id': False})
        # th
        res = super(AccountPartialReconcile, to_unlink).unlink()
        # no
        for to_rec in pairs_to_rec:
            to_rec.reconcile()
        return res