一句话:用多阶段编程将 Scrap Your Boilerplate 改造成带类型的优化代码生成器,消除泛型编程的性能开销。
泛型编程库(如 Scrap Your Boilerplate,SYB)能消除重复代码,但通常带来显著性能开销,使程序员不得不在简洁但缓慢与冗长但高效之间选择。本文应用结构化多阶段编程技术,将 SYB 从低效的泛型库转变为带类型的优化代码生成器:在编译期生成特化代码,从而在保持高层泛型表达的同时获得优化执行。评估表明,该方法使泛型程序的性能与手写代码相当,兼顾了高层编程与不妥协的性能。
Generic programming libraries such as Scrap Your Boilerplate eliminate the need to write repetitive code, but typically introduce significant performance overheads. This leaves programmers with the regrettable choice between writing succinct but slow programs and writing tedious but efficient programs. Applying structured multi-stage programming techniques transforms Scrap Your Boilerplate from an inefficient library into a typed optimising code generator, bringing its performance in line with hand-written code, and so combining high-level programming with uncompromised performance.