recursion removal under environments with cache … · title recursion removal under environments...

12
Title Recursion Removal under Environments with Cache and Garbage Collection (Program Transformation, Symbolic Computation and Algebraic Manipulation) Author(s) Kakehi, Kazuhiko; Futamura, Yoshihiko Citation 数理解析研究所講究録 (2000), 1125: 1-11 Issue Date 2000-01 URL http://hdl.handle.net/2433/63587 Right Type Departmental Bulletin Paper Textversion publisher Kyoto University

Upload: vuongthu

Post on 18-Sep-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Recursion Removal under Environments with Cache … · Title Recursion Removal under Environments with Cache and Garbage Collection (Program Transformation, Symbolic Computation and

TitleRecursion Removal under Environments with Cache andGarbage Collection (Program Transformation, SymbolicComputation and Algebraic Manipulation)

Author(s) Kakehi, Kazuhiko; Futamura, Yoshihiko

Citation 数理解析研究所講究録 (2000), 1125: 1-11

Issue Date 2000-01

URL http://hdl.handle.net/2433/63587

Right

Type Departmental Bulletin Paper

Textversion publisher

Kyoto University

Page 2: Recursion Removal under Environments with Cache … · Title Recursion Removal under Environments with Cache and Garbage Collection (Program Transformation, Symbolic Computation and

Recursion Removal under Environments with Cacheand Garbage Collection

Kazuhiko KAKEHI* Yoshihiko FUTAMURA\daggerGraduate School of Science and Engineering, School of Science and Engineering,

Waseda University Waseda University

Abstract

Basis of software development is to guarantee productivity and safety. Programming usingrecursion $\mathrm{a}\mathrm{n}\mathrm{d}/\mathrm{o}\mathrm{r}$ garbage collection $(\mathrm{G}\mathrm{C})$ satisfies these basis, with sacrificing execution time.Recursion removal, which transforms recursive programs into iterative ones, and improvementstoward garbage collection tackle this imbalance of advantages and disadvantages. While garbagecollection has researched intensively with showing their effects, this is not the case for recursionremoval.

This report explains recursion removal $\mathrm{b}\mathrm{r}\mathrm{i}\mathrm{n}\mathrm{g}\mathrm{s}\Leftrightarrow \mathrm{r}\sigma \mathrm{e}\mathrm{a}\mathrm{t}$ refinement toward recursive programsand also ones running with garbage collection under the current computational environmentwith cache. In our experiments, recursion-removed programs run at most 9.1 times faster thanthe original at gcc and 5.7 times faster at Common Lisp.

1 Introduction

Good software development requires productiv-ity and safety, that is, what programmers in-tend should be easily expressed in programminglanguages and programs should run as intendedwithout errors.

Programming with recursion is said to beeasy: easy to write, easy to verify and easy tomaintain; such recursively written programs un-fortunately run slowly compared with iterativeones in current computer environments. Recur-sion removal, which trarisforms recursive pro-grams into iterative ones, has therefore great im-portance, but its implementation in compilers israre except tail recursion removal.

Memory management is necessary for pro-gram execution. In imperative languages mem-ory operations like malloc and free are used.They complicate the large development, becauseprogrammers have to krlow whole lifetime of

memory areas, otherwise needed data is over-written or unnecessary data remains unnoticedforever, which results in quite hard-to-remedybugs. Under environments with garbage collec-tion (GC for abbreviation) operations for acquir-ing memory area like cons are needed for pro-grammers, because garbage collector as a sub-process collects memory areas which are not re-ferred to any more. Thus GC solves problemsof memory management and makes program-ming easy, as recursion removal is; thus newprogramming languages like Java start to adoptthis technique. As is pointed out frequently,however, programs using garbage collection runslowly.

This report, based on [10], explains throughanalysing program behaviors and experimentsthat recursion removal brings great effects on ex-ecution time, and additionally time for garbagecollection. Especially we believe the latterpoint, garbage collection, casts new viewpoint

*JSPS Research Felow, $\mathrm{k}\mathrm{a}\mathrm{z}\otimes \mathrm{f}\mathrm{u}\mathrm{t}\mathrm{a}\mathrm{n}\mathrm{u}\mathrm{r}\mathrm{a}$ . info. waseda. $\mathrm{a}\mathrm{c}$ . jp$\mathrm{t}_{\mathrm{f}\mathrm{u}\mathrm{t}\mathrm{a}\mathrm{m}}\mathrm{u}\mathrm{r}\mathrm{a}\otimes \mathrm{f}\mathrm{u}\mathrm{t}\mathrm{a}\mathrm{m}\mathrm{u}\mathrm{r}\mathrm{a}$.inf $0$ .waseda. $\mathrm{a}\mathrm{c}$ .jp

数理解析研究所講究録1125巻 2000年 1-11 1

Page 3: Recursion Removal under Environments with Cache … · Title Recursion Removal under Environments with Cache and Garbage Collection (Program Transformation, Symbolic Computation and

to compile-time garbage collection.This reports consists of the following sec-

tions. Section 2 shows recursion removal meth-ods and expected refinements, which will be ver-ified by experiments with gcc in the followingSection 3. Here we observe effects of recursionremoval are greatly influenced by cache. Sec-tion 4 explains improvements toward programsunder garbage collection environments and showresults at Common Lisp. Recursion removal ex-hibits good improvement both on execution and$\mathrm{G}\mathrm{C}$ , but in some cases overheads outweigh it.Section 5 summarizes related works, and finallySection 6 concludes.

2 Recursion removal

As [6] explained recursion has an advantage tomake program development easy, but iterativeprograms run faster on von Neumann-style com-puters than recursive ones. This fact drives re-searches of recursion removal from [3], but itsimplementation in compilers are quite rare ex-cept for tail recursion, which can be easily trans-lated into iteration.

2.1 Effects expected from recursionremoval

By recursion removal we can improve these threepoints.

costs of recursive calls Recursive programsneed recursive calls in their execution.This requires calling stacks and con-sumes much time for pushing and poppingthem. Iterative programs eliminate recur-sive calls, and gain faster execution.

locality of space Elimination of recursivecalls has much larger meaning for exe-cution time in current computer environ-ments. Today’s processors take advantageof cache memory. Cache is a quite fast butsmall memory area closely located at theprocessor. Due to its size, programs haveto be configured to utilize it efficiently. Re-cursive programs and iterative ones have

great difference here, as the contrast isexemplified in Figure 1. Recursion failsto meet this, because recursion requiresstacks and this worsens locality. Itera-tive programs, in the contrary, only needsome fixed size of memory and refer to thearea continually, and locality of referenceis much higher than recursion.

possibility of inlining One more advantageof iterative programs are possibility to beinlined. Un-inlined subroutines are calledseparately and take time. Recursive rou-tines are not possible to be inlined, whilecompilers can inline iterative ones. Recur-sion removal eliminate this calling penal-ties.

We have also to be aware of overheads intro-duced by recursion removal. In some transla-tions, recursion removal newly introduces extracalculation or data structure, and they some-times spoil or worsen execution time.

2.2 Methods

We need to fix the aim of our recursion removal.The definition of recursion removal we give hereis: to translate recursive programs into itera-tive ones without increasing computational com-plexity and using stacks. This definition givestwo restrictions. Considering this transforma-tion aims at speed up of original programs, theformer, complexity, is quite reasonable. Thelatter, stack, is also acceptable, considering theessence of executing recursion is stacks and thatis what we want to eliminate.

Here we give an overview of recursion re-moval presented in [7]. This method, with basison accumulating parameters, aims at linear re-cursion, in which at most one recursive call ap-pears in its definition. The top left program ofFigure 2 is the general form of right linear re-cursive programs, which has a recursive call onits right side. Transformation of this target pro-gram differs from its auxiliary function $a$ . Theyutilized the following two properties of auxiliaryfunctions.

2

Page 4: Recursion Removal under Environments with Cache … · Title Recursion Removal under Environments with Cache and Garbage Collection (Program Transformation, Symbolic Computation and

Figure 1: Recursive and iterative calls and their cache behavior

$f(x)=\mathrm{i}\mathrm{f}p(x)$

then $b(x)$

else $a(c(X), f(d(X)))$$floop’(x)=\mathrm{i}\mathrm{f}p(x)$

floop$(X)=\mathrm{i}\mathrm{f}p(x)$ then $b(x)$

then $b(x)$ else doelse do $v$ $:=c(x);w:=v;u:=x$

$v:=c(x);u:=x$ while $\neg p(d(u))$ dowhile $\neg p(d(u))$ do $u:=d(u)$

$u:=d(u)$ $w:=a’(w, C(u))$$v:=h(v, u)$ odod $a(w, b(d(u)))$

return $a(v, b(d(u)))$ return $v$

od od

Figure 2: Right linear recursive program $f$ (left top) and its iterative form floop using a cumulativefunction (left bottom); another iterative form floop’ using left-pseudo-associativity (right)

3

Page 5: Recursion Removal under Environments with Cache … · Title Recursion Removal under Environments with Cache and Garbage Collection (Program Transformation, Symbolic Computation and

(1) cumulative functions We can recursionremove by finding a cumulative function $h(v, u)$

of the auxiliary function $a$ . $h$ has to $\mathrm{S}\mathrm{a}\mathrm{t}\mathrm{i}\mathrm{s}\mathfrak{g}r$ un-der the condition $\neg p(u)$

$a(v, f(u))=a(h(v,u),$ $f(d(u)))$

for any expression $v$ . Note that $h$ cannot haverecursive calls to $f$ or any hee variables.

$h$ can be easily found when $a$ is associative.

$a(v, f(u))$ $=$ $a(v, a(c(u), f(d(u))))$

$=$ $a(a(v, c(u)),$ $f(d(u)))$

implies $h(v, u)=a(v, C(u))$ . Consider $g(x)$ :

$g(x)=\mathrm{i}\mathrm{f}p(_{X)}$

then $b(x)$

else $c_{1}(x)+c_{2}(x)\cross g(d(x))$

The auxiliary function of $g(x)$ doesn’t have asso-ciativity, but its program is recursion-removableusing two cumulative functions $h_{1}$ and $h_{2}$ intothe following form:

gloop$(_{X})=$

if $p(x)$ then $b(x)$

else do$v_{1}:=c_{1}(x);v_{2}:=c_{2}(x);u:=x$

while $\neg p(d(u))$

do $u:=d(u)$$v_{1}:=h_{1}(v_{1}, v_{2}, u)$

$v_{2}:=h_{2}(v_{1}, v_{2}, u)$ odreturn $v_{1}+v_{2}\cross b(d(u))$

od

with

$h_{1}(v_{1}, v_{2}, u)$ $=$ $v_{1}+v_{2}\cross c_{1}(u)$ ,$h_{2}(v_{1}, v_{2}, u)$ $=$ $v_{2^{\mathrm{X}C}2(u)}$ .

(2) $1\mathrm{e}\mathrm{f}\mathrm{t}-\mathrm{P}\mathrm{s}\mathrm{e}\mathrm{u}\mathrm{d}\mathrm{o}-\mathrm{a}\mathrm{S}\mathrm{S}\mathrm{o}\mathrm{C}\mathrm{i}\mathrm{a}\mathrm{t}\mathrm{i}_{\mathrm{V}}\mathrm{i}\mathrm{t}\mathrm{y}$ While appendis associative, the core operation cons does nothave associativity. This hinders recursion re-moval by cumulative functions. Here we focuson rplacd or rplaca, which replace cdr and carpart of the cons cell pointed by the first argu-ment with the second, and returns the pointer

to the cons cell. These functions has pseudo-associativity and we utilize this property fortransformation.

Definition of $1\mathrm{e}\mathrm{f}\mathrm{t}-\mathrm{P}\mathrm{s}\mathrm{e}\mathrm{u}\mathrm{d}_{0}- \mathrm{a}S\mathrm{s}\mathrm{o}\mathrm{C}\mathrm{i}\mathrm{a}\mathrm{t}\mathrm{i}\mathrm{v}\mathrm{i}\mathrm{t}\mathrm{y}$ isgiven as:

Let $a(x, y)$ a function which hasside-effects and returns the pointerto $x.$ $a$ is $1\mathrm{e}\mathrm{f}\mathrm{t}- \mathrm{p}_{\mathrm{S}}\mathrm{e}\mathrm{u}\mathrm{d}\mathrm{o}$ -associative if$a’$ , which is called as a realizationfunction of $a$ , exists and satisfies thefollowing two equations:

$a(x, y)$ $=$ prog$(a^{J}(x, y),$ $X)$

$a(X, a(y, Z))$ $=$ prog$(a’(a(\prime X,y),$ $z),$ $X)$

where prog$(u, v)$ evaluates $u$ and $v$ ,and returns the value of $v$ .

Finding $a’$ makes recursion removal possi-ble from a right linear recursive program $f(x)$

to $floop’(X)$ in Figure 2. Now we can recur-sion remove programs with cons $(a, b)$ by regard-ing it as rplacd$(\mathrm{l}\mathrm{i}\mathrm{s}\mathrm{t}(a), b)$ . In case $a(x, y)=$$\mathrm{r}\mathrm{p}\mathrm{l}\mathrm{a}\mathrm{c}\mathrm{d}(x, y)$ , taking prog$(a(x, y),$ $y)$ as $a’(x, y)$

satisfies the equations presented previously.

3 Experiments in gcc

First tests of recursion removal were done undergcc on Sun Ultra 5 running $\mathrm{S}\mathrm{u}\mathrm{n}\mathrm{O}\mathrm{S}5.6_{\backslash }$

, whichuses $\mathrm{U}\mathrm{l}\mathrm{t}\mathrm{r}\mathrm{a}\mathrm{S}_{\mathrm{P}}\mathrm{a}\mathrm{r}\mathrm{c}\mathrm{I}\mathrm{I}\mathrm{i}$ , a recent cpu with sufficientprimary cache, and on Macintosh Color ClassicII running $\mathrm{N}\mathrm{e}\mathrm{t}\mathrm{B}\mathrm{S}\mathrm{D}1.3$ , where 68030, an olderand slow cpu with few cache, resides. Detailsof environments appears at Table 1. Subjectprograms are numeric functions $c$ and $g$ , whichcalculate $\lceil\frac{x}{2}\rceil$ for non-negative integer $x$ and $\frac{x+1}{2}$

for integer $x\geq 2$ respectively:

$c(x)=\mathrm{i}\mathrm{f}x=0$

then $0$

else $x-c(x-1)$

$g(x)=\mathrm{i}\mathrm{f}_{X}=2$

then $\frac{3}{2}$

else $1+ \frac{x-1}{x}\cdot g(x-1)$

Figure 3 plots results of $g’ \mathrm{s}$ 1000 calculationsfor various arguments. This figure shows

4

Page 6: Recursion Removal under Environments with Cache … · Title Recursion Removal under Environments with Cache and Garbage Collection (Program Transformation, Symbolic Computation and

Figure 3: Results of numeric function $g$ at $\mathrm{g}\mathrm{c}\mathrm{c}$ : on UltraSparcIIi (left) and on 68030 (right)

Table 1: System details

1. UltraSparcIIi shows much greater im-provement (at most 9.1 times faster inthe figure) than 68030 (regularly 1.5 timesfaster);

2. a break appears around 2,000 in Ultra-SparcIIi’s recursive results.

The second is what Subsection 2.2 explained:cache miss appears over 2,000 for recursion in$\mathrm{U}\mathrm{l}\mathrm{t}\mathrm{r}\mathrm{a}\mathrm{s}_{\mathrm{P}}\mathrm{a}\mathrm{r}\mathrm{c}\mathrm{I}\mathrm{I}\mathrm{i}$ and never for iteration. A tiny pri-mary cache and no secondary cache don’t workfor either recursion or iteration in 68030. To-day’s processors have adequate cache for min-imizing speed gap between memory and pro-cessors, and this example shows recursion re-moval suits the current computing environments$\mathrm{s}\mathrm{y}\sigma \mathrm{r}\mathrm{e}\mathrm{a}\mathrm{t}\mathrm{l}$.

Experiments in other environments, thatis UltraSparc, Pentium and $\mathrm{P}_{\mathrm{o}\mathrm{W}\mathrm{e}\mathrm{r}}\mathrm{p}\mathrm{c}$ , showedscattering in improvements; calculating $\mathrm{c}$ withan argument 6,000 becomes 1.3 times faster in

one environment and 16.9 times faster in an-other for example. What is in common is, how-ever, the more arguments become, the more ef-fects of recursion removal is in recent processorshaving cache of adequate size.

4 Experiments in CommonLisp

Next language we are going to investigate isCommon Lisp. Its language processor has abuild-in garbage collector and this is one point ofour research. Environments for experiments areAllegro Common Lisp (ACL) and Gnu CommonLisp (GCL) running on Sun Ultra Enterprise 2,and Macintosh Common Lisp (MCL) on Power-Macintosh 9600.

5

Page 7: Recursion Removal under Environments with Cache … · Title Recursion Removal under Environments with Cache and Garbage Collection (Program Transformation, Symbolic Computation and

grey: memory space to be checked by GC processdark grey: memory space which is in cache when GC process is invoked

Figure 4: Behaviors of stacks and heap in case temporary data is created: recursion (left) anditeration (right)

4.1 Effects expected for garbage col-lection

This subsection gives analysis of the relation be-tween recursion removal and garbage collection.

What we have to notice that GC process isinfluenced not only by heap cells but other mem-ory area like stacks. GC process, which collectsdead cells, i.e. cells without pointers pointing tothem, for new allocation, uses roots for checkingcells. This root consists of global variables andstacks. If this stack grows, GC process takesmore time to check roots for finding pointers tocells. Stack is also one element of memory, thusthere is memory and cache competition betweenstack and cells.

Considering these issues, following four im-provements on garbage collection are expectedby recursion removal. Note that recursion re-moval only aims at changing stack behavior, notat decreasing total quantity of cells or data cre-ation.

(1) decreasing traversal cost In program-ming by recursion each stack elements pointsto (some part of) argument, data made by thestack and upper stack for next data, as seen inFigure 4. For each time GC process traverses allstack elements pushed and all pointers the stackelements have. Recursion removal reduces thiscost of traversal by minimizing stacks to somefixed size and reducing pointers to ones needed

for current execution. A considerable effect canbe expected because root scanning can take upto 70% of the total GC cost [4]. Additionally, it-erative programs generated by recursion removaldecrease the number of pointers, pointing onlyto middle of argument lists, top and middle ofgenerating lists, and one of the current tempo-rary result.

(2) shortening lifetime Decreasing pointerschanges lifetime of cells or data. Consider thecase where temporary results are required toproceed calculation which is illustrated in Fig-ure 4. In recursive case, every temporary re-sult is pointed by each stack element, surviv-ing long until its calculation terminates. Iter-ative programs, on the contrary, only need thecurrent result, and once the next temporary re-sult is gained the previous is discarded. Thislifetime shortening also applies to intermediatedata passed between two functions. Interme-diate data are not pointed by global variables.When an element of the intermediate list is used,iterative programs replace pointer from the ele-ment to the next, implying there are no pointersto data already consumed by the outer iterativeprogram.

This lifetime shortening has great meaningsto garbage collection. It does not only reducecells or data to be checked by GC process. Thequantity of the free space after one garbage col-lection widens and the duration between GCs

6

Page 8: Recursion Removal under Environments with Cache … · Title Recursion Removal under Environments with Cache and Garbage Collection (Program Transformation, Symbolic Computation and

becomes longer. Total cell allocation doesn’tchange by recursion removal, then this decreaseof frequency implies decrease of GC invocation.

(3) memory competition In a fixed mem-ory, growing stacks pressurize heap area and in-creases ffequency of garbage collection. Thisimplies recursion essentially increases the num-ber of invoking GC process. Recursion-removedprograms can have larger heap, and the smallerinvocation of $\mathrm{G}\mathrm{C}$ .

find its realization function utilizing the auxil-iary function.

Generally, good improvements have achievedfor both of total and GC time, at most 5.7times faster on total and 19.8 times faster on$\mathrm{G}\mathrm{C}$ . The bottom part of figures, plotting, showssequences of each garbage collection time. Re-markable in iteration are:

$\bullet$ each of GC time are kept under 200 msec,on average 150 msec;

(4) cache competition As Section 3 pointedout, recursion removal restrains cache miss byminimizing stack size. This also applies togarbage collect.ion. Recursive programs refer tostack elements, data or cells, and arguments,and GC process checks them all: they conflicton cache, and when GC process is invoked onlyrecently referred items remains in cache, as Fig-ure 4 shows, resulting in longer garbage collec-tion. Smaller number of stack elements reducescache miss and speed up GC process. This effectis massive for programs generating temporaryresults. Reachable data is the most recently cre-ated one, and it is hardly conceivable that this isswept out of cache when GC process is invoked.

4.2 Consing functions

First experiments are programs using conses,that is, merge, halve and mergesorts. The firsttwo are independent functions which do not callother recursive functions, $\mathrm{w}$. hile the last is acompound function which is composed of plu-ral functions.

Figure 5 shows results of 50 times compu-tation to merge two ascending lists of length30,000, and results to halve a list of length60,00050 times. halve takes one list and halve it,and returns a new cons cell which have pointersin car and cdr parts to halved two lists:

halve$((31254))=((324)$ (15)$)$

The auxiliary function of halve is not a singlecons but a more complicated one, but we can

$\bullet$ frequency of GC invocation is reduced.

Change in frequency differs on its execution con-dition like heap size, and sometimes GC processis invoked more hequently in recursion removedfunctions than the original recursive ones. Inany case, recursion removal reduces each GCtime.

Results of mergesorts is shown in Figure 6.Mergesorts can take two forms: one is con-structed in a top-down manner, tree-recursivelyhalving and merging a list; the other is con-structed in a bottom-up manner, recursively con-tinuing to $\mathrm{m}\mathrm{e}\mathrm{r}_{\dot{\mathrm{o}}}\circ \mathrm{e}$ neighboring two lists. While allparts of bottom-up can be recursion-removed,the calling function of top-down is tree-recursiveand all but this can be iterative. The figuresshows results of 5 times sorting of one uniformrandom sequence of length 60,000 generated byRandom Data Server [8].

While the top-down mergesort doesn’t showrefinement by recursion removal as good as in-dependent functions due to its tree structure,the bottom-up one, in which all parts can berecursion removed, is improved a little more.Reduction of GC time is not so much as inde-pendent functions like merge. This is because(a) frequency doesn’t change so much; (b) eachGC time of the recursive are kept small. Inthis mergesorts, we have expected effects of life-time shortening for intermediate data are cre-ated, but it is not noticeable in this results. It istrue inlining is possible here, but it is not doneunder environments experimented with.

7

Page 9: Recursion Removal under Environments with Cache … · Title Recursion Removal under Environments with Cache and Garbage Collection (Program Transformation, Symbolic Computation and

Figure 5: Results of independent functions at Common Lisp: merge (left) and halve (right)

Figure 6: Results of mergesorts at Common Lisp: top-down (lefl) and bottom-up (right)

8

Page 10: Recursion Removal under Environments with Cache … · Title Recursion Removal under Environments with Cache and Garbage Collection (Program Transformation, Symbolic Computation and

ACL GCL MCL

Figure 7: Results of numeric functions at Common Lisp: $g$

ACL GCL MCL

Figure 8: Results of numeric functions at Common Lisp: another $g$

4.3 Numeric functions

Now results of numeric functions, which createsnot cons cells but temporarily calculated datain heap, will be shown. Here applies the anal-ysis of temporary data in Subsection 4.1. Ex-ecuted functions are $c$ of integer type and $g$ ofdouble float type which appear in Subsection 3.Figure 7 shows results of calculating $g$ with anargument 60,00010 times, which shows typicalcharacteristics.

Disappointingly almost all of total timeworsened. One reason is these recursion-removed functions requires two cumulative func-tions and introduce more variables (see gloop inSubsection 2.2). One more reason is, as [11] ex-plains, recursion removal changes computationfrom smaller numbers into computation fromlarger, complicated numbers. Interesting hereis garbage collection. Indeed computation andgenerated data increase due to overheads, total

and each GC time decreases in ACL and GCL.In this method, reduction of GC frequency

is hard to notice due to increase of computation.To confirm this benefit, we have checked resultsof another recursion removal. This transforma-tion follows the evaluation strategy of ‘left-mostinner-most’ (call-by-value). We have to be awareof the following points in case of this transfor-mation:

$\bullet$ the inverse of descent functions $d^{-1}(x)$ isneeded,

$\bullet$ conditions $p(x)$ have to be $‘=’$ ;

otherwise auxiliary stacks or lists are requiredto store the chain of $x,$ $d(X),$ $d^{2}(x),$

$\ldots$ . Our nu-meric examples, $g$ for instance, fits them andeasily translated.

Figure 8 shows the result of $g$ . This timegood performance of execution was achieved aswell as garbage collection. Following the same

9

Page 11: Recursion Removal under Environments with Cache … · Title Recursion Removal under Environments with Cache and Garbage Collection (Program Transformation, Symbolic Computation and

evaluation strategy extra computation or vari-ables are not needed any more. We also noticethat the frequency of garbage collection has de-creased. There is no change in data creation,so we can conclude that this decrease is due tolifetime shortening introduced by recursion re-moval.

5 Related Works

As is mentioned in Section 1, recursion re-moval has energetically studied. Most notableis Burstall and Darlington [3]. This transfor-mation basically utilized template matching toachieve recursion removal. Similar transforma-tion as our cumulative functions is [1] for ex-ample. Cohen [5] focused on redundant recur-$s$ive calls. One of recent works is Harrison andKhoshnevisan [9]. They utilized FP [2], whichinvestigated function-level reasoning, for achiev-ing recursion removal. These methods intro-duced so far transform basically numeric func-tions into iterative forms, and don’t mentiongeneral consing functions. Another recent workby Liu and Stoller [11] introduced quite simi-lar technique as our pseudo-associativity, andshowed also similar results. Yet they don’t thinkof benefits brought by recursion removal or ben-efits of cache.

On effects of garbage collection, Cheng,Harper and Lee [4] mentioned that in the worstcase scanning costs of roots take up to 70% ofgarbage collection time. Their observation fitsthis report and we can say recursion removal canbe the candidate to eliminate that time.

by introducing overheads. Garbage collectionalso benefits from recursion removal especiallyby the effects of reduction of traversal cost andcache competition.

There are two directions to tackle: powerof transformation and automation. As Subsec-tion 4.3 showed, recursion removal by cumula-tive functions didn’t succeed in improving exe-cution. We have to figure out how to circum-vent introduction of overheads and achieve suc-cessful transformation, like emulation of eval-uation strategies. Current methods explainedhere don’t fit for automation yet due to de-pendency on heuristics. We are now trying toautomate these methods, especially one usingpseudo-associativity, by analyzing consing struc-tures and making independent from heuristics.

References

[1] J. Arsac and Y. Kodratoff. Some techniquesfor recursion removal from recursive func-tions. ACM Transactions on ProgrammingLanguages and Systems, $4(2):295^{-322}$ , Apr.1982.

[2] J. Backus. Can programming be liberatedfrom the von Neumann style? a functionalstyle and its algebra of programs. Commu-nications of the ACM, $21(8):613^{-641}$ , Aug.1978.

[3] R. Burstall and J. Darlington. A Rans-formation System for Developing RecursivePrograms. Journal of the Association forComputing Machinery, $24(1):44-67$ , Jan.1977.

6 Conclusion and FutureWorks

This report showed the effects of recursion re-moval on total execution and garbage collection,with data by gcc and Common Lisp. Due togood cache utilization, functions have high pos-sibility to become faster and this has effects tocombined functions. In some kinds of programs,however, recursion removal worsens execution

[4] P. Cheng, R. Harper, and P. Lee. Gener-ational stack collection and profile-drivenpretenuring. In Proceedings of the 1998ACM SIGPLAN Conference on Program-ming Language Design and Implementa-$t\dot{i}on(PLDI)$ , pages 162-173, 1998.

[5] N. Cohen. Eliminating redundant recursivecalls. ACM Transactions on ProgrammingLanguages and Systems, $5(3):265-299$, Jan.1983.

10

Page 12: Recursion Removal under Environments with Cache … · Title Recursion Removal under Environments with Cache and Garbage Collection (Program Transformation, Symbolic Computation and

[6] L. Colussi. Recursion as an effective step inprogram development. A CM Transactionson Programming Languages and Systems,$6(1):55^{-6\mathit{7}}$ , Jan. 1984.

[7] Y. Futamura and H. Ootani. Recursion re-moval rules for linear recursive programsand their effectiveness. Computer Soflware(Japanese), $15(3):38-4\mathit{9}$ , May 1998.

[8] Y. Futamura, H. Ootani, K. Aoki, andN. Futamura. Fast generation of ran-dom permutations with simple indexes.Computer Software (Japanese), $14(6):56-$

73, Nov. 1997.

[9] P. Harrison and H. Khoshnevisan. A newapproach to recursion removal. TheoreticalComputer Science, 93:91-113, Jan. 1992.

[10] K. Kakehi. Effects of stack and cacheon garbage collection (Japanese). Mas-ter’s thesis, Department of Information andComputer Science, Graduate School of Sci-ence and Engineering, Waseda University,Feb. 1999.

[11] Y. Liu and S. Stoller. From recursionto iteration: what are the optimizations?Technical report, Computer Science De-partment, Indiana University, July 1999.

11