1<!doctype html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<html>
3<head>
4<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
5<meta http-equiv="content-style-type" content="text/css">
6<link rel="stylesheet" type="text/css" href="style.css">
7<title>Optimizations</title>
8</head>
9<body>
10
11<script type="text/javascript" language="JavaScript">
12<!--
13if (window.self==window.top)
14  document.write('<a class="largebutton" target="_top" href="../index.html#manual/optimizations.html">ProGuard index</a> <a class="largebutton" target="_top" href="http://www.saikoa.com/dexguard">DexGuard</a> <a class="largebutton" target="_top" href="http://www.saikoa.com/">Saikoa</a> <a class="largebutton" target="other" href="http://sourceforge.net/projects/proguard/">Sourceforge</a>')
15//-->
16</script>
17<noscript>
18<a class="largebutton" target="_top"  href="../index.html#manual/optimizations.html">ProGuard index</a>
19<a class="largebutton" target="_top"  href="http://www.saikoa.com/dexguard">DexGuard</a>
20<a class="largebutton" target="_top"  href="http://www.saikoa.com/">Saikoa</a>
21<a class="largebutton" target="other" href="http://sourceforge.net/projects/proguard/">Sourceforge</a>
22</noscript>
23
24<h2>Optimizations</h2>
25
26The optimization step of ProGuard can be switched off with the
27<a href="usage.html#dontoptimize"><code>-dontoptimize</code></a> option. For
28more fine-grained control over individual optimizations, experts can use the
29<a href="usage.html#optimizations"><code>-optimizations</code></a> option,
30with a filter based on the optimization names listed below. The filter works
31like any <a href="usage.html#filters">filter</a> in ProGuard.
32<p>
33
34The following wildcards are supported:
35
36<table cellspacing="10">
37<tr><td valign="top"><code><b>?</b></code></td>
38    <td>matches any single character in an optimization name.</td></tr>
39<tr><td valign="top"><code><b>*</b></code></td>
40    <td>matches any part of an optimization name.</td></tr>
41</table>
42
43An optimization that is preceded by an exclamation mark '<b>!</b>' is
44<i>excluded</i> from further attempts to match with <i>subsequent</i>
45optimization names in the filter. Make sure to specify filters correctly,
46since they are not checked for potential typos.
47<p>
48
49For example,
50"<code>code/simplification/variable,code/simplification/arithmetic</code>"
51only performs the two specified peephole optimizations.
52<p>
53
54For example, "<code>!method/propagation/*</code>" performs all optimizations,
55except the ones that propagate values between methods.
56<p>
57
58For example,
59"<code>!code/simplification/advanced,code/simplification/*</code>" only
60performs all peephole optimizations.
61<p>
62Some optimizations necessarily imply other optimizations. These are then
63indicated. Note that the list is likely to change over time, as optimizations
64are added and reorganized.
65<p>
66
67<dl>
68<dt><code><b>class/marking/final</b></code></dt>
69<dd>Marks classes as final, whenever possible.</dd>
70
71<dt><code><b>class/unboxing/enum</b></code></dt>
72<dd>Simplifies enum types to integer constants, whenever possible.</dd>
73
74<dt><code><b>class/merging/vertical</b></code></dt>
75<dd>Merges classes vertically in the class hierarchy, whenever possible.</dd>
76
77<dt><code><b>class/merging/horizontal</b></code></dt>
78<dd>Merges classes horizontally in the class hierarchy, whenever possible.</dd>
79
80<dt><div>(&rArr; <code>code/removal/advanced</code>)</div>
81    <code><b>field/removal/writeonly</b></code></dt>
82<dd>Removes write-only fields.</dd>
83
84<dt><code><b>field/marking/private</b></code></dt>
85<dd>Marks fields as private, whenever possible.</dd>
86
87<dt><div>(&rArr; <code>code/simplification/advanced</code>)</div>
88    <code><b>field/propagation/value</b></code></dt>
89<dd>Propagates the values of fields across methods.</dd>
90
91<dt><code><b>method/marking/private</b></code></dt>
92<dd>Marks methods as private, whenever possible (<i>devirtualization</i>).</dd>
93
94<dt><div>(&rArr; <code>code/removal/advanced</code>)</div>
95    <code><b>method/marking/static</b></code></dt>
96<dd>Marks methods as static, whenever possible (<i>devirtualization</i>).</dd>
97
98<dt><code><b>method/marking/final</b></code></dt>
99<dd>Marks methods as final, whenever possible.</dd>
100
101<dt><div>(&rArr; <code>code/removal/advanced</code>)</div>
102    <code><b>method/removal/parameter</b></code></dt>
103<dd>Removes unused method parameters.</dd>
104
105<dt><div>(&rArr; <code>code/simplification/advanced</code>)</div>
106    <code><b>method/propagation/parameter</b></code></dt>
107<dd>Propagates the values of method parameters from method invocations to
108    the invoked methods.</dd>
109
110<dt><div>(&rArr; <code>code/simplification/advanced</code>)</div>
111    <code><b>method/propagation/returnvalue</b></code></dt>
112<dd>Propagates the values of method return values from methods to their
113    invocations.</dd>
114
115<dt><code><b>method/inlining/short</b></code></dt>
116<dd>Inlines short methods.</dd>
117
118<dt><code><b>method/inlining/unique</b></code></dt>
119<dd>Inlines methods that are only called once.</dd>
120
121<dt><code><b>method/inlining/tailrecursion</b></code></dt>
122<dd>Simplifies tail recursion calls, whenever possible.</dd>
123
124<dt><code><b>code/merging</b></code></dt>
125<dd>Merges identical blocks of code by modifying branch targets.</dd>
126
127<dt><code><b>code/simplification/variable</b></code></dt>
128<dd>Performs peephole optimizations for variable loading and storing.</dd>
129
130<dt><code><b>code/simplification/arithmetic</b></code></dt>
131<dd>Performs peephole optimizations for arithmetic instructions.</dd>
132
133<dt><code><b>code/simplification/cast</b></code></dt>
134<dd>Performs peephole optimizations for casting operations.</dd>
135
136<dt><code><b>code/simplification/field</b></code></dt>
137<dd>Performs peephole optimizations for field loading and storing.</dd>
138
139<dt><div>(&rArr; <code>code/removal/simple</code>)</div>
140    <code><b>code/simplification/branch</b></code></dt>
141<dd>Performs peephole optimizations for branch instructions.</dd>
142
143<dt><code><b>code/simplification/string</b></code></dt>
144<dd>Performs peephole optimizations for constant strings.</dd>
145
146<dt><div>(<i>best used with</i> <code>code/removal/advanced</code>)</div>
147    <code><b>code/simplification/advanced</b></code></dt>
148<dd>Simplifies code based on control flow analysis and data flow
149    analysis.</dd>
150
151<dt><div>(&rArr; <code>code/removal/exception</code>)</div>
152    <code><b>code/removal/advanced</b></code></dt>
153<dd>Removes dead code based on control flow analysis and data flow
154    analysis.</dd>
155
156<dt><div>(&rArr; <code>code/removal/exception</code>)</div>
157    <code><b>code/removal/simple</b></code></dt>
158<dd>Removes dead code based on a simple control flow analysis.</dd>
159
160<dt><code><b>code/removal/variable</b></code></dt>
161<dd>Removes unused variables from the local variable frame.</dd>
162
163<dt><code><b>code/removal/exception</b></code></dt>
164<dd>Removes exceptions with empty try blocks.</dd>
165
166<dt><code><b>code/allocation/variable</b></code></dt>
167<dd>Optimizes variable allocation on the local variable frame.</dd>
168</dl>
169<p>
170
171ProGuard also provides some unofficial settings to control optimizations, that
172may disappear in future versions. These are Java system properties, which
173can be set as JVM arguments (with <code>-D.....)</code>:
174<dl>
175<dt><code><b>maximum.inlined.code.length</b></code> (default = 8 bytes)</dt>
176<dd>Specifies the maximum code length (expressed in bytes) of short methods
177    that are eligible to be inlined. Inlining methods that are too long may
178    unnecessarily inflate the code size.</dd>
179
180<dt><code><b>maximum.resulting.code.length</b></code> (default = 8000 bytes
181    for JSE, 2000 bytes for JME)</dt>
182<dd>Specifies the maximum resulting code length (expressed in bytes) allowed
183    when inlining methods. Many Java virtual machines do not apply just-in-time
184    compilation to methods that are too long, so it's important not to let them
185    grow too large.</dd>
186
187<dt><code><b>optimize.conservatively</b></code> (default = unset)</dt>
188<dd>Allows input code with ordinary instructions intentionally throwing
189    <code>NullPointerException</code>,
190    <code>ArrayIndexOutOfBoundsException</code>, or
191    <code>ClassCastException</code>, without any other useful purposes. By
192    default, ProGuard may just discard such seemingly useless instructions,
193    resulting in better optimization of most common code.</dd>
194</dl>
195
196<hr />
197<address>
198Copyright &copy; 2002-2014
199<a target="other" href="http://www.lafortune.eu/">Eric Lafortune</a> @ <a target="top" href="http://www.saikoa.com/">Saikoa</a>.
200</address>
201</body>
202</html>
203