# Best practices for CPU %



## maxchristensenaudio (Apr 2, 2021)

Hi, I'm currently working on a pretty hefty beast of a library right now and I'm a bit worried about it being too CPU hungry for some systems.
I'm developing it on a M1 Chip Macbook Pro and just from playing 1 note the CPU spikes at around 14% with all FX enabled.
Just now I've realized that I probably need to double the Plate Reverb and legacy delay send effects to achieve the kind of behaviour I'm after.

I would love to hear any tips from more experienced developers regarding performance, what to look out for and also, how to tell my users what minimum specs will be able to handle the library!


----------



## EvilDragon (Apr 3, 2021)

You can't really know minimum specs without testing out your library on a multitude of systems of various configurations...

In a nutshell, all the new FX in K6 are more CPU demanding than older FX (especially Replika), convolution and AET filters are also demanding (in convolution this also depends on the length of IR sample you're loading in), and new K5 filters do require more CPU than old ones, especially ladder and Daft.


----------



## maxchristensenaudio (Apr 3, 2021)

I'm actually just using the plate reverb and legacy delay because you're right in that the new ones really shoot the CPU through the roof. Didn't actually know that the ladder filters were more CPU intensive. I thought we had them on K5 as well?

2 1/2 follow up questions:
- How likely is it that less efficient code (lets say a few hundred or 1000 extra lines of unneded code) impacts CPU performance? I know the code should be as efficient as possible also for the coder but this is probably not the first place to look to reduce CPU performance right?
- Say I don't have a multitude of systems for testing: Do I just sell the library without any mentions to system specs, and offer refunds for people whoose system can't handle the library?
- - Is this something that the pulse download team would handle as well?


----------



## EvilDragon (Apr 3, 2021)

maxchristensenaudio said:


> I thought we had them on K5 as well?


Yeah we did. CPU-wise it's a comparison with legacy <=K4 filters.



maxchristensenaudio said:


> - How likely is it that less efficient code (lets say a few hundred or 1000 extra lines of unneded code) impacts CPU performance? I know the code should be as efficient as possible also for the coder but this is probably not the first place to look to reduce CPU performance right?


Yeah probably not too terrible, in most cases. You wouldn't get much CPU savings there, unless you're doing something really really crazy.



maxchristensenaudio said:


> - Say I don't have a multitude of systems for testing: Do I just sell the library without any mentions to system specs, and offer refunds for people whoose system can't handle the library?


This is why beta testing exists where you send out your library to various people and gather feedback on how it performs 



maxchristensenaudio said:


> - Is this something that the pulse download team would handle as well?


Unsure, but probably not.


----------



## d.healey (Apr 3, 2021)

If you want to know if it's the script causing issues you can just bypass everything else.


----------



## berto (Apr 4, 2021)

check the ON Listener lines and as Evildragon once suggested , make it work only when needed with if statements...

and if you have convolution IRs that are too long, well that's a problem...


----------



## maxchristensenaudio (Apr 10, 2021)

berto said:


> check the ON Listener lines and as Evildragon once suggested , make it work only when needed with if statements...
> 
> and if you have convolution IRs that are too long, well that's a problem...


which comment about ON Listener are you referring to berto?


----------



## Vartio (Apr 10, 2021)

Use legacy filters where ever possible. I've made a rule of swapping any other filters to legacy in kontakt. Especially when used on groups the filter cpu hit can multiply very quickly. Theres a small difference to the sound (in context it's nothing I cant live with, besides if the filter sweep is the main event, I'll use a proper plugin for that on the channel) but it keeps the cpu happy!


----------



## EvilDragon (Apr 10, 2021)

That would really depend what sort of library is in question. Old filters are... old. New ones sound much much better, especially if you're doing synth or hybrid stuff. It's worth the CPU.



Vartio said:


> besides if the filter sweep is the main event, I'll use a proper plugin for that on the channel)



That won't be polyphonic tho


----------



## berto (Apr 11, 2021)

maxchristensenaudio said:


> which comment about ON Listener are you referring to berto?


if you have anything in the LCB that refers to syncing, timing, or anything that happens at every specific time, make it work only when needed. Like if KSP has to adapt to a BPM change, make it happen only when there is a BPM change, so that it does not check all the time for a BPM change.
something like this (as per Evildragon's suggestion in another thread)
`on listener
if ($DURATION_QUARTER # $prev_quarter)
if ($NI_SIGNAL_TYPE = $NI_SIGNAL_TIMER_BEAT)
call time_set {adjust all timings and durations}
$prev_quarter := $DURATION_QUARTER
end if
end if
end on`

Also if Kontakt CPU usage is not zero when idle (no transport running, no note input) then something is not right in the script (most probably the LCB)


----------



## maxchristensenaudio (Apr 29, 2022)

Ok I'm back at this issue again and I noticed something weird.

CPU will actually be LOWER if the DAW buffer setting is lower.
At 1024 buffer size the CPU will hover around 30%
at 64 buffer size the CPU is only at 11% .... ?

I don't think there's much I can do to get it lower.
I'm using ALL modulation and modulator slots that Kontakt is offering me, new filters and cabinet fx in some cases and I'm not willing to compromise on that.
I just hope that some lesser PCs will be able to run it...


----------



## berto (Apr 29, 2022)

is Kontakt CPU meter "0" when Kontakt and transport are idle, or does it fluctuate ?


----------



## maxchristensenaudio (May 1, 2022)

berto said:


> is Kontakt CPU meter "0" when Kontakt and transport are idle, or does it fluctuate ?


it's at 0%


----------



## berto (May 1, 2022)

maxchristensenaudio said:


> it's at 0%


Therefore On listener code seems to be ok ….


----------



## maxchristensenaudio (May 1, 2022)

berto said:


> Therefore On listener code seems to be ok ….


I'm afraid it's a bit inconsistent. Checking it again today and the CPU does hover around 0-4% when idle. It can't be the listener though because it may only run if played_voices # 0
And the CPU counter doesn't change when I bypass the instrument script
Though it does seem to be better at lower buffer settings this time. At 512 it stays around 0% at 64 it hover slightly higher


----------



## berto (May 1, 2022)

In my experience, when idle it needs to be 0 without fluctuating.

But if there was a problem in counting the played voices the LCB could still be triggered. 

do you have any LFO or step sequence that goes on without key being pressed ?


----------



## EvilDragon (May 1, 2022)

LCB is always triggered and at the very least does that check for played voices.


----------

