grame-cncm / faust

Functional programming language for signal processing and sound synthesis
http://faust.grame.fr
Other
2.59k stars 325 forks source link

Slow compilation #1010

Open sletz opened 7 months ago

sletz commented 7 months ago

From Dario Sanfilippo

Speaking of the compiler being slow when using partial application, see this code snippet below:

gainAttenuation(isLogDomain, th, att, hold, rel, x) = scaler ~ _
    with {
        scaler(s) = ba.if(isLogDomain, logDomainScaler, linearScaler) , debugSig
            with {
                //peak = peakHoldCascade(32, att + hold, x) * (1.0 - satAmount) + th * satAmount;
                peak = att + holdScaled , x @ (.025 * SR) : peakHoldCascade(32);
                holdScaled = hold * sss;
                peakUnhold = .025 , x : peakHoldCascade(32);
                linearEnvUnhold = max(th, peakUnhold) : smoothing;
                linearEnv = max(th, peak) : smoothing;
...

peakHoldCascade(32) instantiates 32 peakHolders inside. If I give holdScaled as a param, which also has a long tree inside with 32 instantiations, without using basic syntax, it will be duplicated inside each instance of the peakHolders inside peakHoldCascade of the function peak, so things escalate exponentially in that case.

Using basic syntax like I'm doing here cuts compilation times by a factor of 30 or 40. Really a lot.