summaryrefslogtreecommitdiffstats
path: root/docs/manual/optimizations.html
blob: e4c96b6f7c5b7d9c677a38b103b2baa86496b5d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<!doctype html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<meta http-equiv="content-style-type" content="text/css">
<link rel="stylesheet" type="text/css" href="style.css">
<title>Optimizations</title>
<script type="text/javascript" language="JavaScript">
<!--
if (window.self==window.top)
  window.top.location.replace("../index.html#"+window.location.pathname+window.location.hash);
else {
  var hash="#"+window.location.pathname.replace(window.top.location.pathname.replace("index.html", ""), "");
  if (window.top.location.hash!=hash)
    window.top.location.hash=hash;
}
//-->
</script>
</head>
<body>

<h2>Optimizations</h2>

The optimization step of ProGuard can be switched off with the
<a href="usage.html#dontoptimize"><code>-dontoptimize</code></a> option. For
more fine-grained control over individual optimizations, experts can use the
<a href="usage.html#optimizations"><code>-optimizations</code></a> option,
with a filter based on the optimization names listed below. The filter works
like any <a href="usage.html#filters">filter</a> in ProGuard.
<p>

The following wildcards are supported:

<table cellspacing="10">
<tr><td valign="top"><code><b>?</b></code></td>
    <td>matches any single character in an optimization name.</td></tr>
<tr><td valign="top"><code><b>*</b></code></td>
    <td>matches any part of an optimization name.</td></tr>
</table>

An optimization that is preceded by an exclamation mark '<b>!</b>' is
<i>excluded</i> from further attempts to match with <i>subsequent</i>
optimization names in the filter. Make sure to specify filters correctly,
since they are not checked for potential typos.
<p>

For example,
"<code>code/simplification/variable,code/simplification/arithmetic</code>"
only performs the two specified peephole optimizations.
<p>

For example, "<code>!method/propagation/*</code>" performs all optimizations,
except the ones that propagate values between methods.
<p>

For example,
"<code>!code/simplification/advanced,code/simplification/*</code>" only
performs all peephole optimizations.
<p>
Some optimizations necessarily imply other optimizations. These are then
indicated. Note that the list is likely to change over time, as optimizations
are added and reorganized.
<p>

<dl>
<dt><code><b>class/marking/final</b></code></dt>
<dd>Marks classes as final, whenever possible.</dd>

<dt><code><b>class/merging/vertical</b></code></dt>
<dd>Merges classes vertically in the class hierarchy, whenever possible.</dd>

<dt><code><b>class/merging/horizontal</b></code></dt>
<dd>Merges classes horizontally in the class hierarchy, whenever possible.</dd>

<dt><div>(&rArr; <code>code/removal/advanced</code>)</div>
    <code><b>field/removal/writeonly</b></code></dt>
<dd>Removes write-only fields.</dd>

<dt><code><b>field/marking/private</b></code></dt>
<dd>Marks fields as private, whenever possible.</dd>

<dt><div>(&rArr; <code>code/simplification/advanced</code>)</div>
    <code><b>field/propagation/value</b></code></dt>
<dd>Propagates the values of fields across methods.</dd>

<dt><code><b>method/marking/private</b></code></dt>
<dd>Marks methods as private, whenever possible (<i>devirtualization</i>).</dd>

<dt><div>(&rArr; <code>code/removal/advanced</code>)</div>
    <code><b>method/marking/static</b></code></dt>
<dd>Marks methods as static, whenever possible (<i>devirtualization</i>).</dd>

<dt><code><b>method/marking/final</b></code></dt>
<dd>Marks methods as final, whenever possible.</dd>

<dt><div>(&rArr; <code>code/removal/advanced</code>)</div>
    <code><b>method/removal/parameter</b></code></dt>
<dd>Removes unused method parameters.</dd>

<dt><div>(&rArr; <code>code/simplification/advanced</code>)</div>
    <code><b>method/propagation/parameter</b></code></dt>
<dd>Propagates the values of method parameters from method invocations to
    the invoked methods.</dd>

<dt><div>(&rArr; <code>code/simplification/advanced</code>)</div>
    <code><b>method/propagation/returnvalue</b></code></dt>
<dd>Propagates the values of method return values from methods to their
    invocations.</dd>

<dt><code><b>method/inlining/short</b></code></dt>
<dd>Inlines short methods.</dd>

<dt><code><b>method/inlining/unique</b></code></dt>
<dd>Inlines methods that are only called once.</dd>

<dt><code><b>method/inlining/tailrecursion</b></code></dt>
<dd>Simplifies tail recursion calls, whenever possible.</dd>

<dt><code><b>code/merging</b></code></dt>
<dd>Merges identical blocks of code by modifying branch targets.</dd>

<dt><code><b>code/simplification/variable</b></code></dt>
<dd>Performs peephole optimizations for variable loading and storing.</dd>

<dt><code><b>code/simplification/arithmetic</b></code></dt>
<dd>Performs peephole optimizations for arithmetic instructions.</dd>

<dt><code><b>code/simplification/cast</b></code></dt>
<dd>Performs peephole optimizations for casting operations.</dd>

<dt><code><b>code/simplification/field</b></code></dt>
<dd>Performs peephole optimizations for field loading and storing.</dd>

<dt><div>(&rArr; <code>code/removal/simple</code>)</div>
    <code><b>code/simplification/branch</b></code></dt>
<dd>Performs peephole optimizations for branch instructions.</dd>

<dt><code><b>code/simplification/string</b></code></dt>
<dd>Performs peephole optimizations for constant strings.</dd>

<dt><div>(<i>best used with</i> <code>code/removal/advanced</code>)</div>
    <code><b>code/simplification/advanced</b></code></dt>
<dd>Simplifies code based on control flow analysis and data flow
    analysis.</dd>

<dt><div>(&rArr; <code>code/removal/exception</code>)</div>
    <code><b>code/removal/advanced</b></code></dt>
<dd>Removes dead code based on control flow analysis and data flow
    analysis.</dd>

<dt><div>(&rArr; <code>code/removal/exception</code>)</div>
    <code><b>code/removal/simple</b></code></dt>
<dd>Removes dead code based on a simple control flow analysis.</dd>

<dt><code><b>code/removal/variable</b></code></dt>
<dd>Removes unused variables from the local variable frame.</dd>

<dt><code><b>code/removal/exception</b></code></dt>
<dd>Removes exceptions with empty try blocks.</dd>

<dt><code><b>code/allocation/variable</b></code></dt>
<dd>Optimizes variable allocation on the local variable frame.</dd>
</dl>
<p>

ProGuard also provides some unofficial settings to control optimizations, that
may disappear in future versions. These are Java system properties, which
can be set as JVM arguments (with <code>-D.....)</code>:
<dl>
<dt><code><b>maximum.inlined.code.length</b></code> (default = 8 bytes)</dt>
<dd>Specifies the maximum code length (expressed in bytes) of short methods
    that are eligible to be inlined. Inlining methods that are too long may
    unnecessarily inflate the code size.</dd>

<dt><code><b>maximum.resulting.code.length</b></code> (default = 8000 bytes
    for JSE, 2000 bytes for JME)</dt>
<dd>Specifies the maximum resulting code length (expressed in bytes) allowed
    when inlining methods. Many Java virtual machines do not apply just-in-time
    compilation to methods that are too long, so it's important not to let them
    grow too large.</dd>

<dt><code><b>optimize.conservatively</b></code> (default = unset)</dt>
<dd>Allows input code with ordinary instructions intentionally throwing
    <code>NullPointerException</code>,
    <code>ArrayIndexOutOfBoundsException</code>, or
    <code>ClassCastException</code>, without any other useful purposes. By
    default, ProGuard may just discard such seemingly useless instructions,
    resulting in better optimization of most common code.</dd>
</dl>

<hr />
<noscript><div><a target="_top" href="../index.html" class="button">Show menu</a></div></noscript>
<address>
Copyright &copy; 2002-2013
<a target="other" href="http://www.lafortune.eu/">Eric Lafortune</a>.
</address>
</body>
</html>