robbielyman / seamstress

seamstress is an art engine
GNU General Public License v3.0
123 stars 12 forks source link

fix high CPU usage due to ableton link threads #120

Closed p3r7 closed 8 months ago

p3r7 commented 8 months ago

identifying the source of high CPU usage

i used Instruments.app from XCode. you just have to launch it and filter on the "seamstress" process name.

we get:

image

from a 30s run, we can see that 2 threads are responsible for the most of the CPU time, both linked to ableton link (clock.Link_Beat_Reference.loop and clock.Fabric.loop).

the other loops take way less CPU time in comparison.

the "fix"

my fix certainly isn't right or the best way to proceed.

adding a sleep at the begining of the clock.Link_Beat_Reference.loop seem to drastically reduce the CPU usage by half. ableton link seem to still continue working.

doing the same thing to clock.Fabric.loop seems to make seamstress very laggy.

so there are more stuff to explore but the issue is around those 2 threads.

robbielyman commented 8 months ago

thank you so much for looking into this, i was truly mystified. 13% CPU on my machine with the change i just pushed feels much more reasonable... i'll go ahead and merge!

p3r7 commented 8 months ago

11% on mine, even w/ a heavy script (washi)!