We introduce a just-in-time runtime program transformation strategy based on repeated recursion unfolding. Our online program optimization generates several versions of a recursion differentiated by the minimal number of recursive steps covered. The base case of the recursion is ignored in our technique. Our method is introduced here on the basis of single linear direct recursive rules. When a recursive call is encountered at runtime, first an unfolder creates specializations of the associated recursive rule on-the-fly and then an interpreter applies these rules to the call. Our approach reduces the number of recursive rule applications to its logarithm at the expense of introducing a logarithmic number of generic unfolded rules. We prove correctness of our online optimization technique and determine its time complexity. For recursions which have enough simplifyable unfoldings, a super-linear is possible, i.e. speedup by more than a constant factor. The necessary simplification is problem-specific and has to be provided at compile-time. In our speedup analysis, we prove a sufficient condition as well as a sufficient and necessary condition for super-linear speedup relating the complexity of the recursive steps of the original rule and the unfolded rules. We have implemented an unfolder and meta-interpreter for runtime repeated recursion unfolding with just five rules in Constraint Handling Rules (CHR) embedded in Prolog. We illustrate the feasibility of our approach with simplifications, time complexity results and benchmarks for some basic tractable algorithms. The simplifications require some insight and were derived manually. The runtime improvement quickly reaches several orders of magnitude, consistent with the super-linear speedup predicted by our theorems.
翻译:我们提出了一种基于重复递归展开的即时运行时程序变换策略。该在线程序优化技术生成递归的多个版本,这些版本通过所覆盖的最小递归步数进行区分。我们的方法忽略了递归的基本情况。本文以单线性直接递归规则为基础介绍该方法。当在运行时遇到递归调用时,首先由展开器动态生成相关递归规则的特化版本,随后解释器将这些规则应用于该调用。我们的方法将递归规则的应用次数减少至其对数值,代价是引入对数数量的通用展开规则。我们证明了该在线优化技术的正确性并确定了其时间复杂度。对于具有足够可简化展开的递归,可能实现超线性加速,即加速比超过常数因子。必要的简化是问题相关的,需在编译时提供。在加速分析中,我们证明了关于原始规则与展开规则的递归步复杂度之间关系的超线性加速充分条件及充要条件。我们在嵌入Prolog的约束处理规则(CHR)中,仅用五条规则实现了运行时重复递归展开的展开器与元解释器。我们通过简化案例、时间复杂度结果及若干基本可处理算法的基准测试,说明了该方法的可行性。简化过程需要一定洞察力且目前为手动推导。运行时改进迅速达到数个数量级,与定理预测的超线性加速相一致。