On Sat, Oct 24, 2015 at 11:39 PM, Leif Theden <[email protected]> wrote: > Greetings! In response to a conversation in another thread, I've put > together some changes to the pyglet Clock that offer some performance > benefits between 25% - 80% during use based on my benchmarks. This clock > doesn't change the API or behavior of the Clock and is a 'drop in > replacement'. > [...] > > The only drawback from this heap clock is that 'soft scheduling' is > impacted. By my benchmarks, it typically executes at the same speed or > slower as the sorted-list Clock (the one in use now). Soft-scheduling > requires a sorted list of events to correctly find a free spot in the > schedule so that several events do not overlap and create usage spikes, so > the heap-clock has to create a sorted copy of the event queue. Perhaps > another mechanism for soft scheduling can be used, however, I have not > investigated alternative methods.
Hello, I haven't studied the code in detail, but I'd like to point out that: 1. Every sorted list is also a heap [0] 2. Python's sorting algorithm is very good at lists that are "almost" sorted (i.e. a few elements/subsequences out of place) [1] So, for soft scheduling you might want to sort the list, insert the event, and then leave the list sorted. This would make the next soft schedule faster, as long as intervening heapq operations don't shuffle the list *completely*. I think it'd be worth exploring but haven't tested/benchmarked it myself. [0] https://docs.python.org/3/library/heapq.html : "heap.sort() maintains the heap invariant!" [1] https://hg.python.org/cpython/file/3.5/Objects/listsort.txt : "3sort", "%sort" -- You received this message because you are subscribed to the Google Groups "pyglet-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/pyglet-users. For more options, visit https://groups.google.com/d/optout.
