Commit 80f1b69
authored
Speed up removing old orders and quotes (#4151)
# Description
The incremental solvable orders query so far blindly inserted updated
orders in to the set of open orders and then ran a filtering step over
ALL open orders and quotes separately.
This is pretty wasteful since the new/updated orders are significantly
fewer than the set of ALL orders and 3 of 4 things we check we only need
to check on the new/updated orders.
Also we don't have to go over ALL quotes if we just remove the quotes
together with the orders.
# Changes
- determine whether to insert or remove orders based on the new
information returned by the incremental DB query
- whenever we remove an order we also remove the associated quote to
never run do a `.retain()` on ALL quotes
- still do a `.retain()` on the open orders to find expired orders as
the incremental orders query will not flag those - while we still scan
the whole list twice the most complicated checks could be moved to the
part that only runs on the updated orders so this `.retain()` still is a
lot faster than before.
## How to test
Measured performance with tempo
Retain orders went from 2.5ms to 283µs
and we dropped the 6.6ms from retaining quotes completely
Before
<img width="1298" height="298" alt="Screenshot 2026-02-13 at 08 13 38"
src="https://github.com/user-attachments/assets/fd375cf9-851b-4a67-be36-4dae00c49461"
/>
After
<img width="1333" height="271" alt="Screenshot 2026-02-13 at 08 13 24"
src="https://github.com/user-attachments/assets/2feabd4c-64fa-4b49-ab1b-8bedb42d9711"
/>1 parent 0c04766 commit 80f1b69
1 file changed
Lines changed: 25 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
612 | 612 | | |
613 | 613 | | |
614 | 614 | | |
615 | | - | |
| 615 | + | |
| 616 | + | |
616 | 617 | | |
617 | | - | |
618 | | - | |
619 | | - | |
620 | | - | |
621 | | - | |
622 | | - | |
623 | | - | |
624 | | - | |
625 | | - | |
626 | | - | |
627 | | - | |
628 | | - | |
629 | 618 | | |
630 | 619 | | |
631 | 620 | | |
| |||
645 | 634 | | |
646 | 635 | | |
647 | 636 | | |
648 | | - | |
649 | | - | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
650 | 653 | | |
651 | | - | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
652 | 661 | | |
653 | 662 | | |
654 | 663 | | |
| |||
0 commit comments