mirror of
https://github.com/airwindows/airwindows.git
synced 2026-05-15 06:05:55 -06:00
[GH-ISSUE #33] CPU load #26
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/airwindows#26
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @sjaehn on GitHub (Jun 26, 2021).
Original GitHub issue: https://github.com/airwindows/airwindows/issues/33
Hi Chris,
I'm looking to speed up my ports of your Airwindows plugins as some of them are really hungry for CPU. I couldn't find too much. But there is one significant point to save CPU time. The
pow()function.pow()is likely the most expensive of the standard<cmath>functions. Even more expensive thantan()on the most of the CPUs.Thus, it's much faster to code
x*xinstead ofpow(x,2). And alsox*x*xandx*x*x*xare faster thanpow(). OK, modern compilers PLUS optimization flags (-O3AND-ffast-math) may end up at the same. But there is a big difference without optimization. See https://stackoverflow.com/questions/2940367/what-is-more-efficient-using-pow-to-square-or-just-multiply-it-with-itself .And even bigger differences are for integer
pow(2,x)versus bit shifting (1 << x). As in the stereo floating point dither section. See https://stackoverflow.com/questions/12556906/are-2n-exponent-calculations-really-less-efficient-than-bit-shifts .I was able to save some 1/10 to 1/5 of the DSP load for XRegion by substituting the
pow()functions.@sjaehn commented on GitHub (Jul 10, 2021):
Chris, you are right. As long as you compile with optimization flags (your default way), you are on the safe side for
pow(). You correctly mentioned this in your last stream. But packagers and others who want to implement your plugins into sth. else (e.g., Surge) should keep their eyes open.But there is still sth. else to safe CPU even in the presence of optimization flags. Omit type converting, if possible.
float,double, andlong double. Whereas the most of thefloatanddoubleoperations are almost at the same speed for the most modern architectures,long doubleis still significantly slower. Unless, if you have a compiler that breaks downlong doubletodoubleanyway ;-).I was able to safe some 50% of CPU by brutal (= not generally recommended!) declaration of everything as
floatfor XRegion plus remove of the floating point dither section.@airwindows commented on GitHub (Jul 10, 2021):
You can of course do this as much as you like: it's MIT-licensed and you can make all your own versions, changed however you wish.
It will never be officially Airwindows style to run all the algorithms as single precision float. Ever. But if you did that, of course the floating point dither would be of no use to you :)
I do think it's possible that you'll run into some issues with some of the biquad stuff as biquads can have problems with low resolution numbers, but most things will still probably work. Some of the extreme control settings might crash your computer or produce artifacts if the algorithms are made to run on only floats, if the settings were exploiting the smaller amounts of error (expensively) gained in my versions.