Opened 56 minutes ago

Last modified 47 minutes ago

#37126 new New feature

Make Task and TaskResult comparable

Reported by: Johannes Maron Owned by:
Component: Tasks Version: dev
Severity: Normal Keywords:
Cc: Johannes Maron Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Jake and I have been discussing changes to the Task framework for 6.2 with a focus on performance and versatility.

Python's queue.PriorityQueue implementation requires objects to be comparable.

Since the base implementation of a Task implements a priority, it only makes sense to provide basic comparability based on the priority and date.

Dataclasses have a neat order=True attribute to make this stupidly simple.

Change History (1)

comment:1 by Johannes Maron, 47 minutes ago

I would also suggest adding a custom eq method. We only need to include id and a simple string comparison is much quicker. Benchmarks N = 100_000_000:

Original == (equal)             18.614s  (186.1 ns/call)
Original == (not equal)         7.452s  (74.5 ns/call)
Id-only == (equal)              4.434s  (44.3 ns/call)
Id-only == (not equal)          4.423s  (44.2 ns/call)
Note: See TracTickets for help on using tickets.
Back to Top