grame-cncm / faust

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

Rust allocation #1002

Closed sletz closed 8 months ago

sletz commented 8 months ago

In the Rust backend:

pub struct mydsp {
    fSampleRate: i32,
    fConst0: F32,
    fHslider0: F32,
    fHslider1: F32,
    fRec0: [F32;3],
}

impl FaustDsp for mydsp {
    type T = F32;

    fn new() -> mydsp { 
        mydsp {
            fSampleRate: 0,
            fConst0: 0.0,
            fHslider0: 0.0,
            fHslider1: 0.0,
            fRec0: [0.0;3],
        }
    }
...

should be rewritten (for big arrays):

pub struct mydsp {
    fSampleRate: i32,
    fConst0: F32,
    fHslider0: F32,
    fHslider1: F32,
    fRec0: Box<[f32; 3]>,
}

impl FaustDsp for mydsp {
    type T = F32;

    fn new() -> mydsp { 
        mydsp {
            fSampleRate: 0,
            fConst0: 0.0,
            fHslider0: 0.0,
            fHslider1: 0.0,
            fRec0: vec![0.0; 3].into_boxed_slice(),
        }
    }
...
bluenote10 commented 8 months ago

Hm, but then we enforce boxing implicitly, which could prevent usage in embedded scenarios and it could lead to worse performance due to reduced cache locality.

Wasn't this solved in https://github.com/grame-cncm/faust/pull/828 by allowing to opt-in to the default_boxed feature? This already works pretty well for large-sized DSPs.

sletz commented 8 months ago

OK, actually somewhat forgot that discussion ((-;... so nothing to do then.