We present a novel approach for efficient code synthesis from synchronous dataflow specifications. The method avoids duplication of code blocks when compiling SDF graphs regardless of whether a single appearance schedule can be found for the graph or not. This also means that we can use schedules that require minimal buffer memory but are not single appearance schedules. The method has been developed within the compiler for the Rialto language, which we have developed for use as an intermediate language for code synthesis from heterogeneous models of computation. The optimization technique presented in the paper can, however, very well also be used without the Rialto language.