<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Algebraic and Cost-based Optimization of ⋆ Refactoring Sequences</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Martin Kuhlemann</string-name>
          <email>martin.kuhlemann@ovgu.de</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Liang Liang</string-name>
          <email>leon.liangliang@hotmail.com</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Gunter Saake</string-name>
          <email>gunter.saake@ovgu.de</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>University of Magdeburg</institution>
          ,
          <country country="DE">Germany</country>
        </aff>
      </contrib-group>
      <fpage>37</fpage>
      <lpage>48</lpage>
      <abstract>
        <p>Software product lines comprise techniques to tailor a program by selecting features. One approach to implement product lines is to translate selected features into sequenced program transformations which extend a base program. However, a sequence translated from the user selection can be inefficient to execute. In this paper, we show how we optimize sequences of refactoring transformations to reduce the composition time for product line programs.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>
        A feature is a characteristic of a program which is of interest to a user [
        <xref ref-type="bibr" rid="ref14">14</xref>
        ].
Software product lines (SPLs) comprise techniques to tailor the set of features
of a program to user needs [
        <xref ref-type="bibr" rid="ref17">17</xref>
        ]. One technique to implement an SPL is to
define code transformations which successively apply to a base program and add
the desired program characteristics to it. These SPL transformations include
aspects [
        <xref ref-type="bibr" rid="ref32">32</xref>
        ], refinements [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ], refactorings [
        <xref ref-type="bibr" rid="ref18">18</xref>
        ], and others.
      </p>
      <p>
        In SPLs, feature-adding code transformations are abstract operations which
a user selects without knowing their implementation. As a result the user
(unknowingly) may select transformations that undo each other or that override
another transformation’s effects. Such a non-optimal transformation plan may
be selected by accident but may also be meaningful to reuse transformations.1
While the composition result is correct, the composition process is more
expensive than necessary. On the one hand, end-user satisfaction may be increased due
⋆ This paper summarizes and extends the Master’s Thesis of Liang Liang [
        <xref ref-type="bibr" rid="ref21">21</xref>
        ]. An
extended version of this paper with more technical details has been published as a
technical report [
        <xref ref-type="bibr" rid="ref20">20</xref>
        ]. The authors thank Don Batory and Andreas Lu¨bcke for helpful
discussions and for giving hints on earlier versions of this paper. The authors thank
the anonymous reviewers of MDPLE 2010 for additional hints.
1 Suppose in one configuration of an SPL, classes List and ArrayList should switch
names then one of them must be renamed twice, e.g., List 7→ TestList 7→ ArrayList.
In a second configuration, in which only List exists, List should be renamed into
ArrayList, too, and for that both prior refactorings get reused.
to a reduced program composition time. On the other hand, developers benefit
when they must compose a number of SPL programs, e.g., during testing.
      </p>
      <p>In this paper, we lean on database optimization techniques and optimize
sequences of refactorings translated from a user selection of features. We discuss
the theoretical basics as well as our prototype. In case studies we observed that
with our prototype we reduced composition time by up to 81%.
2</p>
    </sec>
    <sec id="sec-2">
      <title>Background</title>
      <p>We introduce the concepts of refactoring along with transformation-based SPLs
as these concepts are issue to optimization, later.
2.1</p>
      <sec id="sec-2-1">
        <title>Refactorings</title>
        <p>
          Refactorings are code transformations that alter the structure of code but do
not alter its functionality [
          <xref ref-type="bibr" rid="ref26">26</xref>
          ]. Refactoring descriptions, like Rename Class, are
templates and so a developer has to provide parameters to make the templates
executable [
          <xref ref-type="bibr" rid="ref25">25</xref>
          ]. For example, to execute a Rename Class refactoring, two
parameters must be defined: the class to rename and the new class name.
        </p>
        <p>
          When a refactoring is parameterized and executed, the refactoring engine
commonly executes two phases. In the verification phase, preconditions are
checked in the code to refactor to ensure its transformation does not alter its
functionality. For any Rename Class refactoring, the refactoring engine will check
whether the class to rename does exist and whether the class created by the
refactoring does not exist [
          <xref ref-type="bibr" rid="ref28">28</xref>
          ].
        </p>
        <p>
          In the transformation phase, transformations are performed on the code
elements specified as parameters for the refactoring. That is, for Rename Class,
the specified class is renamed and every reference to the class is updated [
          <xref ref-type="bibr" rid="ref10">10</xref>
          ].
In the following, we denote a refactoring R, that replaces a code element X by a
code element Y, with RX7→Y.
2.2
        </p>
      </sec>
      <sec id="sec-2-2">
        <title>Transformation-Based Software Product Lines</title>
        <p>
          Features are user-visible program characteristics of an SPL and are selected
to tailor a program of that SPL [
          <xref ref-type="bibr" rid="ref14">14</xref>
          ]. Features can be implemented by code
transformations defined in feature modules [
          <xref ref-type="bibr" rid="ref4">4</xref>
          ]. In SPLs, feature modules are
hidden from the user – the user makes a selection of feature names/descriptions
which is translated into a sequence of program transformations. The program
transformations make the generated program expose the required features.
        </p>
        <p>
          Program transformations in SPLs can implement refactorings in order to
integrate programs, foster reuse, and to tailor non-functional properties of
programs [
          <xref ref-type="bibr" rid="ref18 ref29">18,29</xref>
          ]. Feature modules which host such refactoring transformations are
called refactoring feature modules (RFMs) [
          <xref ref-type="bibr" rid="ref18">18</xref>
          ]. When a user selects features,
that translate to refactorings the structure of the synthesized program is altered
Feature Module F1
Feature Module F1
        </p>
        <p>List
_elements
get()</p>
        <p>Queue
Feature Module R2
Feature Module R3
Feature Module R4
Feature Module R5</p>
        <p>Feature Module R6
Rename class:List 7→TestList</p>
        <sec id="sec-2-2-1">
          <title>Rename class:List 7→ArrayList</title>
        </sec>
        <sec id="sec-2-2-2">
          <title>Rename method:TestList.get 7→pop</title>
        </sec>
        <sec id="sec-2-2-3">
          <title>Rename method:ArrayList.get 7→pop</title>
        </sec>
        <sec id="sec-2-2-4">
          <title>Rename class:TestList 7→ArrayList</title>
        </sec>
        <sec id="sec-2-2-5">
          <title>Rename class:Queue 7→myQueue</title>
        </sec>
        <sec id="sec-2-2-6">
          <title>Rename class:Queue 7→myQueue</title>
        </sec>
        <sec id="sec-2-2-7">
          <title>Rename class:ArrayList 7→Queue</title>
          <p>List
_elements
get()</p>
          <p>Queue
Feature Module C2
Feature Module C3
Feature Module R5
Feature Module R6</p>
        </sec>
        <sec id="sec-2-2-8">
          <title>Rename class:ArrayList 7→Queue</title>
          <p>(a) Running RFM example.</p>
          <p>(b) Optimization result.
compared to a base definition in other SPL transformations, e.g., classes are
named differently.</p>
          <p>In our running example for this paper in Figure 1a, there is one feature
module F1 which defines the base program of the SPL and which is altered by
SPL transformations which follow. That is, there is a number of RFMs, R2 to
R6 which transform the base program of F1. When a user selects feature F1 and
does not select any RFM, the configured program will be a copy of the code
of F1. When a user selects all features (top-down order), F1 along with R2 to
R6 the composed program will expose the functionality of F1 but will have a
different structure. Specifically, when all features are selected, then the resulting
code will be a class myQueue with no members and a class Queue with a field
elements and a method pop.
3</p>
        </sec>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>Optimizing Refactoring Sequences</title>
      <p>
        We consider two ways to optimize a given sequence of refactorings: optimizing the
verification phases and optimizing the transformation phases of the sequenced
refactorings. Optimizing verification phases in a sequence of refactorings is to
check whether preceding refactorings establish preconditions of later
refactorings [
        <xref ref-type="bibr" rid="ref16 ref28">28,16</xref>
        ]. When a refactoring’s precondition is satisfied by an earlier
refactoring in a sequence, the program does not have to be validated for the latter
refactoring, and thus not parsed and traversed for verification issues –
performance can be gained by fusing verification phases [
        <xref ref-type="bibr" rid="ref16 ref28">28,16</xref>
        ].
      </p>
      <p>Base</p>
      <p>R2</p>
      <p>R3</p>
      <p>R4</p>
      <p>R5</p>
      <p>R6
predecessor
dependency
set−up
dependency</p>
      <p>Optimizing the transformation phases for a sequence of refactorings is to
fuse transformations performed by successive refactorings. For example, we can
fuse two successive refactorings if both refactorings rename the same class,
e.g., R4TestList7→ArrayList• R2List7→TestList can be replaced by C2 List7→ArrayList. As we
do not have to traverse the code twice to parse it, to set up the type system,
to look for calls to the method, and to update them, we expect performance
benefits. The optimizations we propose work without prior code analysis
(algebraic optimization) and with prior code analysis and cost functions (cost-based
optimization).
3.1</p>
      <sec id="sec-3-1">
        <title>Algebraic Optimization</title>
        <p>
          In this work, we concentrate on the concepts for fusing transformation phases
of refactorings to improve composition performance (fusing verification phases
has been analyzed before [
          <xref ref-type="bibr" rid="ref16 ref28">28,16</xref>
          ]). To optimize a given sequence of refactorings,
we reorder sequenced refactorings and fuse them finally. We reorder refactorings
to group refactorings of which transformation phases could be fused according
to fusing rules we define. We identify fusible refactorings by analyzing their
parameters and types.
        </p>
        <p>
          Basic Concept. To optimize the RFM sequence of Figure 1a, we iterate the
sequence of refactorings and calculate fusible refactorings. Two refactorings are
fusible when there is a set-up dependency between them, the complete
precondition of the later refactoring is satisfied by the preceding refactoring, and when the
fused refactoring again is a standard refactoring according to [
          <xref ref-type="bibr" rid="ref10">10</xref>
          ] or the empty
refactoring. For instance, we calculate, that R2List7→TestList could be fused with
R4TestList7→ArrayList to C2List7→ArrayList (see Figure 1b) because the output element
TestList of R2 is the input element of R4 and the fusing result is the standard
refactoring Rename Class; the same for R4 and R6. We then try to reorder R4
and R6 to become successors of R2.
        </p>
        <p>To prevent errors introduced by our reordering, we propose to compute a
dependency graph concept for all refactorings. Especially, we look for two kinds of
dependencies: (1) set-up dependencies toward preceding RFMs where one
preceding refactoring sets up some code elements required by a subsequent refactoring,
and (2) predecessor dependencies toward preceding refactorings where a
preceding refactoring requires another refactoring to establish a required deletion. The
conceptual dependency graph for Figure 1a is given in Figure 2.2</p>
        <p>
          Using the computed dependency graph we try to reorder R4 and R6 according
to their fusibility. However, we only commute refactorings that do not have
predecessor dependencies among each other. Further, we update the parameters
of two commuted refactorings when both expose set-up dependencies toward
the same predecessor refactoring and share fully qualified names. For instance in
Figure 2, we commute R3 with R4 because R4 is fusible with R2. As R3 and R4
both expose set-up dependencies toward R2 and parameters share the identifier
TestList, we update R3 to become C3ArrayList.get7→pop, see Figure 1b. However,
we do not reorder R6 because its predecessor dependency towards R5 disallows
commuting with R5. Finally, we fuse successive refactorings according to our
fusing rules of Table 1, see [
          <xref ref-type="bibr" rid="ref20 ref21">20,21</xref>
          ] for a complete list.
        </p>
        <p>
          Name capture. When a method A is renamed by a Rename Method
refactoring, all methods that override A or that are overridden by A are renamed
accordingly [
          <xref ref-type="bibr" rid="ref10">10</xref>
          ]. Name capture is an error in refactoring that occurs when
methods override each other after a refactoring executed which did not override each
other before the refactoring executed [
          <xref ref-type="bibr" rid="ref25 ref26 ref31">26,25,31</xref>
          ]. When commuting refactorings,
we may not know whether methods referenced in 2 RFMs will override each
other after both RFMs get commuted. Nevertheless, we must guarantee that we
do not introduce name capture, i.e., that the optimized refactoring sequence still
produces the same program. Name capture must also be prevented for fields.3
        </p>
        <p>We present three concepts which avoid name capture. In concept #1, we
track which refactoring parameter (fully qualified name) emerges out of which
2 R2 creates class TestList which is required by R3 and R4. R4 creates class ArrayList
which R6 requires to exist. R5 removes Queue which R6 requires to not exist.
3 A special situation which disallows commuting refactorings occurs when a Move
Method RFM or Inline Method RFM follows an Extract Interface RFM and both
operate the same class.
code element in the base code. By analyzing relationships between the code
elements in the base code we can then decide whether two elements override
each other. In concept #2, we disallow commuting of two refactorings when both
reference methods, e.g., Rename Method refactorings, or when both reference
fields. However, we only must disallow commuting when field or method names
match in the refactorings to be commuted. In concept #3, we define all the
elements, which a refactoring alters, inside feature modules. As a result, we
know all (overridden) methods which are effected by a Rename Method RFM.
Heuristical reordering. Reordering itself can produce performance benefits
for the composition process. For example, when a Rename Field RFM follows
an Encapsulate Field RFM4, then reordering is beneficial though both RFMs
cannot be fused. The reason is that the field to be renamed might be referenced
multiple times in the transformed code but is only referenced once in the getter
and once in the setter method after encapsulating the field. When the field name
is integrated in the generated method names, this optimization is not possible.
For caution in this case, we should disallow commuting Encapsulate Field RFMs
with any other refactoring transforming the field.</p>
        <p>
          Commuting a Hide Method refactoring5 with a Rename Method refactoring
is beneficial. After hiding the method, the composer can reason on the new
visibility qualifier of this hidden method and thus can prune the code traversed
for renaming. For example, if hiding the method push produces a private method
then for renaming push the composer just must traverse the class as no references
outside this class can exist. Similar optimizations are possible for fields.
Random reordering. With the concepts presented so far, we cannnot optimize
the sequence R3 RenameClass:C37→C4 • R2 MoveClass:C27→C3 • R1 RenameClass:C17→C2
because we cannot detect any fusibility. We can fuse neither R1 with R2 nor R2
with R3 because the resulting refactoring would be no standard refactoring –
fusing them would exceed our set of operations.6 We also do not detect fusibility
between R1 and R3 because the output identifier of R1 does not match the
input identifier of R3. If we at random commute R1 with R2 or R2 with R3 then
a new fusing chance emerges between (reordered) R1 and (reordered) R3. We
envision to generate sets of refactoring plans during algebraic optimization also
by randomly reordering refactorings and to select the shortest plan for execution.
4 Encapsulate field adds get and set methods for the field to encapsulate [
          <xref ref-type="bibr" rid="ref10">10</xref>
          ]. After
that, the refactoring transformation replaces every reference to the field by a call to
either the get or set method.
5 Hide Method refactoring reduces the visibility of the method as far as possible [
          <xref ref-type="bibr" rid="ref10">10</xref>
          ].
6 We could provide composite refactorings which do renaming and moving within one
step (as shown before [
          <xref ref-type="bibr" rid="ref16">16</xref>
          ]) but we refrained due to the infinit number of possible
refactoring combinations [
          <xref ref-type="bibr" rid="ref16">16</xref>
          ].
        </p>
      </sec>
      <sec id="sec-3-2">
        <title>Cost-based Optimization</title>
        <p>We can analyze the code to be refactored to estimate the execution costs for
individual refactorings. From there we can further optimize a refactoring sequence or
select between alternative sequences. We envision to identify refactorings which
alter distinct parts of a program (possibly, distinct artifact types). If we can
reorder these refactorings to succeed each other, we can parallelize their execution,
i.e., we can load and alter the distinct program parts in parallel. One approach
to identify relevant distinct program parts is to collect visibility qualifiers and
inheritance hierarchies from the program to refactor. If then the visibility of two
code elements is very restricted, e.g., private or protected, and both occur in
different classes (hierarchies) according refactorings perform on distinct pieces of
code and can be executed in parallel.</p>
        <p>As an example, consider the Rename Method
refactorings R3TestList.get7→pop and R7myQueue.pop7→insert where both
methods are analyzed to not override each other or a com- R2 R4
mon method, and to be qualified as protected. Thus, R3 -
and R7 transform distinct parts of a program. In that R7’
case we can infer a parallelization chance and try to make
both refactorings successors. We then can load TestList
and myQueue and their subclasses in parallel and execute Fig. 3. Parallel
R3 and R7 in parallel as shown in Figure 3. We can also RFM execution.
parallelize refactorings which transform private members
of different classes.</p>
        <p>If the visibility of members is private or protected and – in the latter case –
the inheritance hierarchy is small, then according refactorings are expected to be
cheap. By deferring presumably expensive refactorings we increase the chance
that for a longer time the memory is not exceeded by loading code. This reduces
the number of buffer misses (increases performance).</p>
        <p>R3
4</p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>Case Studies</title>
      <p>
        We implemented the basic concept of algebraic optimization of RFMs
prototypically. Currently, a separate optimizer operates RFMs in a step separately before
the composer tool runs. Details can be found in [
        <xref ref-type="bibr" rid="ref20 ref21">20,21</xref>
        ].
4.1
      </p>
      <sec id="sec-4-1">
        <title>Study Setup</title>
        <p>We took programs of different size and purpose as study objects. We composed
the feature modules and took the composer’s runtime. Then we run our optimizer
tool and took its runtime, too. Finally, we composed the optimized sequences and
compared the composer’s runtime to the time of the unoptimized composition,</p>
        <p>r
se
o
p
om
C
t.)
p
(o
r
e
iz
tim
p
O
e
r
u
P</p>
        <p>n
tio
a
iz
tim
p</p>
        <p>O
see Table 2.7 As we do not change the composition of non-RFM features we
prune the studies to only have one non-RFM feature module F1 each.
Simple List. As a proof of concept we applied three different sequences of RFMs
to a conceptual list implementation. In these sequences, we fuse an RFM, which
extracts the interface AbstractList from class List, with reordered RFMs which
all rename the extracted interface. As a result one new refactoring is generated
which extracts the interface with the final name in the first place. In another
sequence, we could not fuse refactorings which had fusing chances due to a
predecessor dependency.</p>
        <p>TankWar. We analyzed TankWar an SPL of arcade games for desktop computer
and cell phone developed prior to this evaluation at Magdeburg University. The
study is still small-scale but provides functionality (in contrast to the Simple
List case).</p>
        <p>
          Workbench.texteditor. In order to analyze the performance effect of
optimizing RFM sequences, we should pay attention to the size of the transformed
program. For that, we reused a large-scale study of the Eclipse8 library
workbench.texteditor from prior work [
          <xref ref-type="bibr" rid="ref19">19</xref>
          ]. To this library, we applied three different
sequences of RFMs with lengths ranging from 10 to 55 RFMs.
7 We used a Microsoft Windows XP Home Edition SP2 on an Intel R CoreTM2 CPU
T5500 @ 1.66GHz, 667MHz FSB, 0.99 GB RAM. The given measurements are
averages of 10 runs, listed one-by-one in [
          <xref ref-type="bibr" rid="ref21">21</xref>
          ]. The optimizer solely generates optimized
and unchanged RFMs into a folder Optimized but does not copy other SPL feature
modules. To measure the composition performance for the optimized RFM sequence,
we manually copied the other feature modules into the Optimized folder. Detecting
name capture is not yet implemented. We implemented five fusing rules.
8 http://www.eclipse.org/
ZipMe. We finally analyzed a study of a compression library ZipMe from prior
work [
          <xref ref-type="bibr" rid="ref18">18</xref>
          ] which showed us that our optimization effort may be worthless and,
thus, derogatory. That is, in the ZipMe study, there is no fusing chance and thus,
the runtime of our optimizer tool directly increases composition time.
        </p>
        <p>In Table 2, we summarize the measured runtimes of the optimizer tool as
well as the runtimes of the composer tool on the unoptimized and on the
optimized RFM sequences. In some cases we gained performance increases, e.g., for
case Workbench.texteditor (c) we gained a performance benefit of 81% through
optimization. In many cases, however, the overall composition time increased
with optimization, i.e., performance decreased. For example, the unoptimized
composition time for case Simple List (a) is 12018.6ms and the optimized
composition time plus the optimizer runtime is 18805ms, i.e., a performance loss of
56%. Nevertheless, we did not fail optimizing. The increased composition time
is mainly caused by the optimizer prototype operating independently from the
composer tool. Times for loading RFMs, thus, contribute to both the composer
and the optimizer tool, and times for writing optimization results arise. When
the optimizer is integrated with the composer tool (possible future work), RFMs
would be loaded only once and the need to write the optimized RFM sequence
to harddisk vanishes. To respect this, we also measured the time for purely
optimizing loaded refactoring sequences. When considering pure optimization time,
we get a significant performance benefit for all cases but the ZipMe case.</p>
        <p>From the measurements we observed that the performance benefit increases
with a growing size of the program to be transformed, the highest performance
benefits were measured for the biggest program (Workbench.texteditor). We also
observed that with a growing number of fusible RFMs, the optimization benefit
increases, too. In the case of ZipMe, the optimizer could not produce a benefit
and, thus, for this case optimization effort is derogatory.</p>
        <p>Threats to Validity. The measurements and benefits depend on the loading
of RFMs. If to load an RFM takes a long time, reducing the number of loads
saves a lot time. The measurements and benefits further depend on the execution
time for a single RFM. If executing a single RFM takes a long time, reducing
the number of executions saves a lot time. The RFM composer tool we used (the
only one we know of) is written for flexibility and not for performance. Thus,
for other RFM composers the numbers may be different.</p>
        <p>Our approach may remove whole subsequences from a sequence of
transformations. This implicitly removes precondition checks of removed
transformations. We did not distinguish composer run times for checks and actions because
we did not change the composer.
5</p>
      </sec>
    </sec>
    <sec id="sec-5">
      <title>Related Work</title>
      <p>
        Researchers composed transformations, refactorings, and their preconditions
before, e.g.,[
        <xref ref-type="bibr" rid="ref13 ref15 ref16 ref28 ref8">28,16,8,15,13</xref>
        ], and formalized refactorings and their preconditions [
        <xref ref-type="bibr" rid="ref25">25</xref>
        ].
In contrast to prior work, we reorder, replace, and update (sequences of)
refactorings in a transformation sequence to create a faster-to-execute sequence of
standard refactorings. To the best of our knowledge, this is new.
      </p>
      <p>
        Dig fuses sequences of refactorings [9, p.95], sequences which were recorded
independently on the same program. He adapts parameters of the refactorings in
order to sequentialize the according refactorings. Similarly, Lynagh fuses
concurrent edits on code and resolves conflicts by commuting and reverting edits [
        <xref ref-type="bibr" rid="ref22">22</xref>
        ].
It may happen that by fusing sequences of edits and refactorings, the resulting
sequence may execute faster than their concatenation (in case this concatenation
works at all). In contrast to prior work, we intend to shrink a single sequence
and for that fuse refactorings and reorder them.
      </p>
      <p>
        Design maintenance systems (DMSs) organize transformations a program
was built from [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ]. DMSs commute transformations, update transformation
parameters [5, p.175], and replace subsequences of transformations [5, p.179] in
order to integrate new transformations and to evolve the program [5, p.179ff].
DMSs compose transformations [5, p.129] but no specific rules are given for how
to do so. We reorder refactorings to fuse them for performance reasons and to
remove superfluous transformations (not in the focus of Baxter [5, p.276]).
      </p>
      <p>
        Researchers describe how to calculate dependencies between transformations
in general and refactorings in particular [
        <xref ref-type="bibr" rid="ref23 ref24">23,24</xref>
        ]. We also compute these
dependencies, so prior research is a basis for our research. Based on dependencies
between refactorings, we introduce fusing rules for transformation phases of
refactorings. Further, we discussed optimizations of refactoring sequences based on
code analyses (cost-based optimization, cf. Sec. 3.2).
      </p>
      <p>
        P´erez derives refactoring sequences that minimize code smells [
        <xref ref-type="bibr" rid="ref27">27</xref>
        ]. We
transform given sequences of refactorings with fusing rules in order to yield
performance benefits for their execution. We cannot imagine how to safely automate
the restructuring process of a program towards a given interface.
      </p>
      <p>
        In our approach, we know generics of all SPL transformations and thus the
transformation’s effects, i.e., we know the effects of refactorings as defined in
RFMs. In general, however, developers may be allowed to define
transformations/rewrites beyond refactorings, e.g., [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ]; transformations of which we maybe
do not know the effects. In those cases, our fusing rules do not apply, as we
maybe do not know the effects of transformations before executing them.
      </p>
      <p>
        Relational algebra organizes a set of algebraic operations users can execute on
databases [
        <xref ref-type="bibr" rid="ref11 ref7">7,11</xref>
        ]. With SQL, a user describes declaratively the data she needs [
        <xref ref-type="bibr" rid="ref30">30</xref>
        ].
The algebra expression translated from the declarative query may be
suboptimal and thus it is optimized algebraically (without table analyses) and cost-based
(with table analyses) [
        <xref ref-type="bibr" rid="ref11 ref12 ref30">12,11,30</xref>
        ]. In distributed database management systems, a
query result can be computed on different systems in parallel to improve query
time [
        <xref ref-type="bibr" rid="ref1 ref12 ref7">1,7,12</xref>
        ]. When generating our SPL program, the selected features are
translated into sequenced program transformations – a sequence which may be
suboptimal. In this paper, we showed how a sequence of refactorings inside RFMs
can be optimized algebraically and cost-based, i.e., without and with analyzing
the code to refactor. In our envisioned cost-based optimization we parallelize
RFMs to improve composition time which then will closely correlate to parallel
database management systems. However, database management systems do not
organize program transformations.
      </p>
      <p>
        Batory et al. related program transformations to category theory and, thus,
sketched the formal basis of our optimizations [
        <xref ref-type="bibr" rid="ref2 ref3">2,3</xref>
        ]. Our fusion rules and
heuristical reordering for refactoring transformations thus implement these abstract
concepts. In addition, we presented ideas on cost-based optimizations of
refactoring sequences.
6
      </p>
    </sec>
    <sec id="sec-6">
      <title>Conclusions</title>
      <p>Product line users tailor programs by selecting features. Selected features can
translate into program transformations which execute sequentially on a base
program. A sequence translated directly from a user selection can be inefficient. In
this paper, we showed how to optimize sequences of refactoring transformations
to reduce the composition time of product line programs. We presented a
prototype and evaluated it in several case studies. We observed that the optimization
reduces the time to compose a program in most cases though not all.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <surname>P.M.G. Apers</surname>
            ,
            <given-names>A.R.</given-names>
          </string-name>
          <string-name>
            <surname>Hevner</surname>
            , and
            <given-names>S.B.</given-names>
          </string-name>
          <string-name>
            <surname>Yao</surname>
          </string-name>
          .
          <article-title>Optimization algorithms for distributed queries</article-title>
          .
          <source>IEEE Transactions on Software Engineering</source>
          ,
          <volume>9</volume>
          (
          <issue>1</issue>
          ):
          <fpage>57</fpage>
          -
          <lpage>68</lpage>
          ,
          <year>1983</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <given-names>D.</given-names>
            <surname>Batory</surname>
          </string-name>
          .
          <article-title>A modeling language for program design and synthesis</article-title>
          .
          <source>Lecture Notes in Computer Science</source>
          ,
          <volume>5316</volume>
          :
          <fpage>39</fpage>
          -
          <lpage>58</lpage>
          ,
          <year>2008</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <given-names>D.</given-names>
            <surname>Batory</surname>
          </string-name>
          .
          <article-title>Using modern mathematics as an fosd modeling language</article-title>
          .
          <source>In Proceedings of the International Conference on Generative Programming and Component Engineering</source>
          , pages
          <fpage>35</fpage>
          -
          <lpage>44</lpage>
          ,
          <year>2008</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <given-names>D.</given-names>
            <surname>Batory</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.N.</given-names>
            <surname>Sarvela</surname>
          </string-name>
          ,
          <article-title>and</article-title>
          <string-name>
            <given-names>A.</given-names>
            <surname>Rauschmayer</surname>
          </string-name>
          .
          <article-title>Scaling step-wise refinement</article-title>
          .
          <source>IEEE Transactions on Software Engineering</source>
          ,
          <volume>30</volume>
          (
          <issue>6</issue>
          ):
          <fpage>355</fpage>
          -
          <lpage>371</lpage>
          ,
          <year>2004</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <given-names>I.D.</given-names>
            <surname>Baxter</surname>
          </string-name>
          .
          <article-title>Transformational maintenance by reuse of design histories</article-title>
          .
          <source>PhD thesis</source>
          ,
          <year>1990</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <given-names>M.</given-names>
            <surname>Bravenboer</surname>
          </string-name>
          ,
          <string-name>
            <given-names>K.T.</given-names>
            <surname>Kalleberg</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Vermaas</surname>
          </string-name>
          , and
          <string-name>
            <given-names>E.</given-names>
            <surname>Visser</surname>
          </string-name>
          . Stratego/XT 0.17.
          <article-title>a language and toolset for program transformation</article-title>
          .
          <source>Science of Computer Programming</source>
          ,
          <volume>72</volume>
          (
          <issue>1-2</issue>
          ):
          <fpage>52</fpage>
          -
          <lpage>70</lpage>
          ,
          <year>2008</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <given-names>S.</given-names>
            <surname>Chaudhuri</surname>
          </string-name>
          .
          <article-title>An overview of query optimization in relational systems</article-title>
          .
          <source>In Proceedings of the Symposium on Principles of Database Systems</source>
          , pages
          <fpage>34</fpage>
          -
          <lpage>43</lpage>
          ,
          <year>1998</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <surname>M.</surname>
          </string-name>
          <article-title>O´ Cinn´eide and</article-title>
          <string-name>
            <given-names>P.</given-names>
            <surname>Nixon</surname>
          </string-name>
          .
          <article-title>Composite refactorings for java programs</article-title>
          .
          <source>In Workshop on Formal Techniques for Java Programs</source>
          , pages
          <fpage>129</fpage>
          -
          <lpage>135</lpage>
          ,
          <year>2000</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9.
          <string-name>
            <given-names>D.</given-names>
            <surname>Dig</surname>
          </string-name>
          .
          <article-title>Automated upgrading of component-based applications</article-title>
          .
          <source>PhD thesis</source>
          , University of Illinois at Urbana-Champaign,
          <year>2007</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          10.
          <string-name>
            <given-names>M.</given-names>
            <surname>Fowler</surname>
          </string-name>
          .
          <article-title>Refactoring: Improving the design of existing code. Addison-Wesley Longman Publishing Co</article-title>
          ., Inc.,
          <year>1999</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          11.
          <string-name>
            <given-names>P.A.V.</given-names>
            <surname>Hall</surname>
          </string-name>
          .
          <article-title>Optimization of single expressions in a relational data base system</article-title>
          .
          <source>IBM Journal of Research and Development</source>
          ,
          <volume>20</volume>
          (
          <issue>3</issue>
          ):
          <fpage>244</fpage>
          -
          <lpage>257</lpage>
          ,
          <year>1976</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          12.
          <string-name>
            <given-names>M.</given-names>
            <surname>Jarke</surname>
          </string-name>
          and
          <string-name>
            <given-names>J.</given-names>
            <surname>Koch</surname>
          </string-name>
          .
          <article-title>Query optimization in database systems</article-title>
          .
          <source>ACM Computing Surveys</source>
          ,
          <volume>16</volume>
          (
          <issue>2</issue>
          ):
          <fpage>111</fpage>
          -
          <lpage>152</lpage>
          ,
          <year>1984</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          13.
          <string-name>
            <given-names>P.</given-names>
            <surname>Johann</surname>
          </string-name>
          and
          <string-name>
            <surname>E. Visser.</surname>
          </string-name>
          <article-title>Fusing logic and control with local transformations: An example optimization</article-title>
          .
          <source>Electronic Notes in Theoretical Computer Science</source>
          ,
          <volume>57</volume>
          :
          <fpage>144</fpage>
          -
          <lpage>162</lpage>
          ,
          <year>2001</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          14.
          <string-name>
            <given-names>K.</given-names>
            <surname>Kang</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Cohen</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Hess</surname>
          </string-name>
          ,
          <string-name>
            <given-names>W.</given-names>
            <surname>Novak</surname>
          </string-name>
          ,
          <article-title>and</article-title>
          <string-name>
            <given-names>A.</given-names>
            <surname>Peterson</surname>
          </string-name>
          .
          <article-title>Feature-oriented domain analysis (FODA) feasibility study</article-title>
          .
          <source>Technical Report CMU/SEI-90-TR-21</source>
          , Software Engineering Institute, Carnegie Mellon University,
          <year>1990</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref15">
        <mixed-citation>
          15.
          <string-name>
            <given-names>G.</given-names>
            <surname>Kniesel</surname>
          </string-name>
          .
          <article-title>A logic foundation for program transformations</article-title>
          .
          <source>Technical Report IAI-TR-2006-1</source>
          , Computer Science Department III, University of Bonn,
          <year>2006</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref16">
        <mixed-citation>
          16. G. Kniesel and
          <string-name>
            <given-names>H.</given-names>
            <surname>Koch</surname>
          </string-name>
          .
          <article-title>Static composition of refactorings</article-title>
          .
          <source>Science of Computer Programming</source>
          ,
          <volume>52</volume>
          (
          <issue>1-3</issue>
          ):
          <fpage>9</fpage>
          -
          <lpage>51</lpage>
          ,
          <year>2004</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref17">
        <mixed-citation>
          17.
          <string-name>
            <given-names>C. W.</given-names>
            <surname>Krueger</surname>
          </string-name>
          .
          <article-title>New methods in software product line practice</article-title>
          .
          <source>Communications of the ACM</source>
          ,
          <volume>49</volume>
          (
          <issue>12</issue>
          ):
          <fpage>37</fpage>
          -
          <lpage>40</lpage>
          ,
          <year>2006</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref18">
        <mixed-citation>
          18.
          <string-name>
            <surname>M. Kuhlemann</surname>
            ,
            <given-names>D.</given-names>
          </string-name>
          <string-name>
            <surname>Batory</surname>
            , and
            <given-names>S.</given-names>
          </string-name>
          <string-name>
            <surname>Apel</surname>
          </string-name>
          .
          <article-title>Refactoring feature modules</article-title>
          .
          <source>In Proceedings of the International Conference on Software Reuse</source>
          , pages
          <fpage>106</fpage>
          -
          <lpage>115</lpage>
          ,
          <year>2009</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref19">
        <mixed-citation>
          19.
          <string-name>
            <surname>M. Kuhlemann</surname>
            ,
            <given-names>D.</given-names>
          </string-name>
          <string-name>
            <surname>Batory</surname>
            , and
            <given-names>C.</given-names>
          </string-name>
          <article-title>K¨astner</article-title>
          .
          <article-title>Safe composition of non-monotonic features</article-title>
          .
          <source>In Proceedings of the International Conference on Generative Programming and Component Engineering</source>
          , pages
          <fpage>177</fpage>
          -
          <lpage>186</lpage>
          ,
          <year>2009</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref20">
        <mixed-citation>
          20.
          <string-name>
            <surname>M. Kuhlemann</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          <string-name>
            <surname>Liang</surname>
            , and
            <given-names>G.</given-names>
          </string-name>
          <string-name>
            <surname>Saake</surname>
          </string-name>
          .
          <article-title>Algebraic and cost-based optimization of refactoring sequences</article-title>
          .
          <source>Technical Report 5</source>
          , Faculty of Computer Science, University of Magdeburg,
          <year>2010</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref21">
        <mixed-citation>
          21.
          <string-name>
            <given-names>L.</given-names>
            <surname>Liang</surname>
          </string-name>
          .
          <article-title>Optimizing sequences of refactorings</article-title>
          .
          <source>Master thesis</source>
          , University of Magdeburg, Germany,
          <string-name>
            <surname>MAR</surname>
          </string-name>
          <year>2010</year>
          . http://wwwiti.cs.uni−magdeburg.de/iti db/publikationen/ps/auto/thesisLiang.pdf.
        </mixed-citation>
      </ref>
      <ref id="ref22">
        <mixed-citation>
          22.
          <string-name>
            <surname>I. Lynagh.</surname>
          </string-name>
          <article-title>An algebra of patches</article-title>
          . http://urchin.earth.li/∼ian/conflictors/paper2006-10-30.pdf,
          <year>2006</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref23">
        <mixed-citation>
          23. T. Mens, G. Kniesel, and
          <string-name>
            <given-names>O.</given-names>
            <surname>Runge</surname>
          </string-name>
          .
          <article-title>Transformation dependency analysis - a comparison of two approaches</article-title>
          .
          <source>In Actes des journ´eees Langages et Mod`eles `a Objets</source>
          , pages
          <fpage>167</fpage>
          -
          <lpage>184</lpage>
          ,
          <year>2006</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref24">
        <mixed-citation>
          24. T. Mens, G. Taentzer, and
          <string-name>
            <given-names>O.</given-names>
            <surname>Runge</surname>
          </string-name>
          .
          <article-title>Analysing refactoring dependencies using graph transformation</article-title>
          .
          <source>Software and Systems Modeling</source>
          ,
          <volume>6</volume>
          (
          <issue>3</issue>
          ):
          <fpage>269</fpage>
          -
          <lpage>285</lpage>
          ,
          <year>2007</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref25">
        <mixed-citation>
          25. T. Mens,
          <string-name>
            <given-names>N. v.</given-names>
            <surname>Eetvelde</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Demeyer</surname>
          </string-name>
          , and
          <string-name>
            <given-names>D.</given-names>
            <surname>Janssens</surname>
          </string-name>
          .
          <article-title>Formalizing refactorings with graph transformations</article-title>
          .
          <source>Software Maintenance and Evolution: Research and Practice</source>
          ,
          <volume>17</volume>
          (
          <issue>4</issue>
          ):
          <fpage>247</fpage>
          -
          <lpage>276</lpage>
          ,
          <year>2005</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref26">
        <mixed-citation>
          26.
          <string-name>
            <given-names>W.F.</given-names>
            <surname>Opdyke</surname>
          </string-name>
          .
          <article-title>Refactoring object-oriented frameworks</article-title>
          .
          <source>PhD thesis</source>
          , University of Illinois at Urbana-Champaign,
          <year>1992</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref27">
        <mixed-citation>
          27.
          <string-name>
            <surname>J. P</surname>
          </string-name>
          <article-title>´erez. Enabling refactoring with HTN planning to improve the design smells correction activity</article-title>
          .
          <source>In BElgian-NEtherlands software eVOLution workshop</source>
          ,
          <year>2008</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref28">
        <mixed-citation>
          28.
          <string-name>
            <surname>D.B. Roberts</surname>
          </string-name>
          .
          <article-title>Practical analysis for refactoring</article-title>
          .
          <source>PhD thesis</source>
          , University of Illinois at Urbana-Champaign,
          <year>1999</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref29">
        <mixed-citation>
          29.
          <string-name>
            <given-names>N.</given-names>
            <surname>Siegmund</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Kuhlemann</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Apel</surname>
          </string-name>
          , and
          <string-name>
            <given-names>M.</given-names>
            <surname>Pukall</surname>
          </string-name>
          .
          <article-title>Optimizing non-functional properties of software product lines by means of refactorings</article-title>
          .
          <source>In Proceedings of the International Workshop on Variability Modelling of Software-intensive Systems</source>
          , pages
          <fpage>115</fpage>
          -
          <lpage>122</lpage>
          ,
          <year>2010</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref30">
        <mixed-citation>
          30.
          <string-name>
            <surname>J.M. Smith</surname>
            and
            <given-names>P.Y.-T.</given-names>
          </string-name>
          <string-name>
            <surname>Chang</surname>
          </string-name>
          .
          <article-title>Optimizing the performance of a relational algebra database interface</article-title>
          .
          <source>Communications of the ACM</source>
          ,
          <volume>18</volume>
          (
          <issue>10</issue>
          ):
          <fpage>568</fpage>
          -
          <lpage>579</lpage>
          ,
          <year>1975</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref31">
        <mixed-citation>
          31.
          <string-name>
            <given-names>P.</given-names>
            <surname>Steyaert</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            <surname>Lucas</surname>
          </string-name>
          ,
          <string-name>
            <given-names>K.</given-names>
            <surname>Mens</surname>
          </string-name>
          , and
          <string-name>
            <surname>T. D'Hondt</surname>
          </string-name>
          .
          <article-title>Reuse contracts: Managing the evolution of reusable assets</article-title>
          .
          <source>ACM SIGPLAN Notices</source>
          ,
          <volume>31</volume>
          (
          <issue>10</issue>
          ):
          <fpage>268</fpage>
          -
          <lpage>285</lpage>
          ,
          <year>1996</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref32">
        <mixed-citation>
          32.
          <string-name>
            <given-names>C.</given-names>
            <surname>Zhang</surname>
          </string-name>
          and
          <string-name>
            <given-names>H.-A.</given-names>
            <surname>Jacobsen</surname>
          </string-name>
          .
          <article-title>Quantifying aspects in middleware platforms</article-title>
          .
          <source>In Proceedings of the International Conference on Aspect-Oriented Software Development</source>
          , pages
          <fpage>130</fpage>
          -
          <lpage>139</lpage>
          ,
          <year>2003</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>