Feldspar / feldspar-compiler

This is the compiler for the Feldspar Language.
Other
22 stars 5 forks source link

Double buffer #154

Closed kffaxen closed 10 years ago

kffaxen commented 10 years ago

Double buffering in sequential loops (forLoop and whileLoop). Improves performance by avoiding deep copies. Copies structs recursively; copying ends at IVars, Pointers and arrays (ordinary and native). Attempts to choose the two state variables intelligently; if the output location is a variable or has native array type, it is used as one of the state variables, and if the type of the state is scalar, the second state variable is the same as the first one, saving the copy in the loop. Pointed-to data in the state is swapped explicitly between the state variables in the loop. This includes arrays, IVars and the target of Pointers. This is necessary to avoid inadvertent sharing of the pointed-to data between the two state variables.

pjonsson commented 10 years ago

(The web ate my review, so duplicate comment)

This is necessary to avoid inadvertent sharing of the pointed-to data between the two state variables.

This invariant is great: it should be a comment in the source code somewhere, perhaps somewhere near shallowCopyWithRefSwap. (But the things "This" refers to should be inlined so that the comment can be read in isolation)

emwap commented 10 years ago

Thank you @kffaxen for the patch and @pjonsson for your thorough review. Could you please amend your branch before I merge it.