/usr/share/doc/julia-doc/html/manual/performance-tips.html is in julia-doc 0.2.1+dfsg-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Performance Tips — Julia Language 0.2.0 documentation</title>
<link rel="stylesheet" href="../_static/julia.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '0.2.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<link rel="top" title="Julia Language 0.2.0 documentation" href="../index.html" />
<link rel="up" title="The Julia Manual" href="index.html" />
<link rel="next" title="Style Guide" href="style-guide.html" />
<link rel="prev" title="Packages" href="packages.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="style-guide.html" title="Style Guide"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="packages.html" title="Packages"
accesskey="P">previous</a> |</li>
<li><a href="http://julialang.org/">Julia</a> / </li>
<li><a href="../index.html">Documentation</a> / </li>
<li><a href="index.html" accesskey="U">The Julia Manual</a> / </li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="performance-tips">
<span id="man-performance-tips"></span><h1>Performance Tips<a class="headerlink" href="#performance-tips" title="Permalink to this headline">¶</a></h1>
<p>In the following sections, we briefly go through a few techniques that
can help make your Julia code run as fast as possible.</p>
<div class="section" id="avoid-global-variables">
<h2>Avoid global variables<a class="headerlink" href="#avoid-global-variables" title="Permalink to this headline">¶</a></h2>
<p>A global variable might have its value, and therefore its type, change
at any point. This makes it difficult for the compiler to optimize code
using global variables. Variables should be local, or passed as
arguments to functions, whenever possible.</p>
<p>Any code that is performance-critical or being benchmarked should be
inside a function.</p>
<p>We find that global names are frequently constants, and declaring them
as such greatly improves performance:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="kd">const</span> <span class="n">DEFAULT_VAL</span> <span class="o">=</span> <span class="mi">0</span>
</pre></div>
</div>
<p>Uses of non-constant globals can be optimized by annotating their types
at the point of use:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="kd">global</span> <span class="n">x</span>
<span class="n">y</span> <span class="o">=</span> <span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">::</span><span class="kt">Int</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
</pre></div>
</div>
<p>Writing functions is better style. It leads to more reusable code and
clarifies what steps are being done, and what their inputs and outputs
are.</p>
</div>
<div class="section" id="avoid-containers-with-abstract-type-parameters">
<h2>Avoid containers with abstract type parameters<a class="headerlink" href="#avoid-containers-with-abstract-type-parameters" title="Permalink to this headline">¶</a></h2>
<p>When working with parameterized types, including arrays, it is best to
avoid parameterizing with abstract types where possible.</p>
<p>Consider the following:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">a</span> <span class="o">=</span> <span class="n">Real</span><span class="p">[]</span> <span class="c"># typeof(a) = Array{Real,1}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">f</span> <span class="o">=</span> <span class="n">rand</span><span class="p">())</span> <span class="o"><</span> <span class="o">.</span><span class="mi">8</span>
<span class="n">push</span><span class="o">!</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span>
<span class="k">end</span>
</pre></div>
</div>
<p>Because <tt class="docutils literal"><span class="pre">a</span></tt> is a an array of abstract type <tt class="docutils literal"><span class="pre">Real</span></tt>, it must be able
to hold any Real value. Since <tt class="docutils literal"><span class="pre">Real</span></tt> objects can be of arbitrary
size and structure, a must be represented as an array of pointers to
individually allocated <tt class="docutils literal"><span class="pre">Real</span></tt> objects. Because <tt class="docutils literal"><span class="pre">f</span></tt> will always be
a <tt class="docutils literal"><span class="pre">Float64</span></tt>, we should instead, use:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">a</span> <span class="o">=</span> <span class="kt">Float64</span><span class="p">[]</span> <span class="c"># typeof(a) = Array{Float64,1}</span>
</pre></div>
</div>
<p>which will create a contiguous block of 64-bit floating-point values
that can be manipulated efficiently.</p>
<p>See also the discussion under <a class="reference internal" href="types.html#man-parametric-types"><em>Parametric Types</em></a>.</p>
</div>
<div class="section" id="type-declarations">
<h2>Type declarations<a class="headerlink" href="#type-declarations" title="Permalink to this headline">¶</a></h2>
<p>In many languages with optional type declarations, adding declarations
is the principal way to make code run faster. This is <em>not</em> the case
in Julia. In Julia, the compiler generally knows the types of all function
arguments, local variables, and expressions.
However, there are a few specific instances where declarations are
helpful.</p>
<div class="section" id="declare-specific-types-for-fields-of-composite-types">
<h3>Declare specific types for fields of composite types<a class="headerlink" href="#declare-specific-types-for-fields-of-composite-types" title="Permalink to this headline">¶</a></h3>
<p>Given a user-defined type like the following:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="k">type</span><span class="nc"> Foo</span>
<span class="n">field</span>
<span class="k">end</span>
</pre></div>
</div>
<p>the compiler will not generally know the type of <tt class="docutils literal"><span class="pre">foo.field</span></tt>, since it
might be modified at any time to refer to a value of a different type.
It will help to declare the most specific type possible, such as
<tt class="docutils literal"><span class="pre">field::Float64</span></tt> or <tt class="docutils literal"><span class="pre">field::Array{Int64,1}</span></tt>.</p>
</div>
<div class="section" id="annotate-values-taken-from-untyped-locations">
<h3>Annotate values taken from untyped locations<a class="headerlink" href="#annotate-values-taken-from-untyped-locations" title="Permalink to this headline">¶</a></h3>
<p>It is often convenient to work with data structures that may contain
values of any type, such as the original <tt class="docutils literal"><span class="pre">Foo</span></tt> type above, or cell
arrays (arrays of type <tt class="docutils literal"><span class="pre">Array{Any}</span></tt>). But, if you’re using one of
these structures and happen to know the type of an element, it helps to
share this knowledge with the compiler:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="k">function</span><span class="nf"> foo</span><span class="p">(</span><span class="n">a</span><span class="p">::</span><span class="n">Array</span><span class="p">{</span><span class="kt">Any</span><span class="p">,</span><span class="mi">1</span><span class="p">})</span>
<span class="n">x</span> <span class="o">=</span> <span class="n">a</span><span class="p">[</span><span class="mi">1</span><span class="p">]::</span><span class="kt">Int32</span>
<span class="n">b</span> <span class="o">=</span> <span class="n">x</span><span class="o">+</span><span class="mi">1</span>
<span class="o">...</span>
<span class="k">end</span>
</pre></div>
</div>
<p>Here, we happened to know that the first element of <tt class="docutils literal"><span class="pre">a</span></tt> would be an
<tt class="docutils literal"><span class="pre">Int32</span></tt>. Making an annotation like this has the added benefit that it
will raise a run-time error if the value is not of the expected type,
potentially catching certain bugs earlier.</p>
</div>
<div class="section" id="declare-types-of-keyword-arguments">
<h3>Declare types of keyword arguments<a class="headerlink" href="#declare-types-of-keyword-arguments" title="Permalink to this headline">¶</a></h3>
<p>Keyword arguments can have declared types:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="k">function</span><span class="nf"> with_keyword</span><span class="p">(</span><span class="n">x</span><span class="p">;</span> <span class="n">name</span><span class="p">::</span><span class="kt">Int</span> <span class="o">=</span> <span class="mi">1</span><span class="p">)</span>
<span class="o">...</span>
<span class="k">end</span>
</pre></div>
</div>
<p>Functions are specialized on the types of keyword arguments, so these
declarations will not affect performance of code inside the function.
However, they will reduce the overhead of calls to the function that
include keyword arguments.</p>
<p>Functions with keyword arguments have near-zero overhead for call sites
that pass only positional arguments.</p>
<p>Passing dynamic lists of keyword arguments, as in <tt class="docutils literal"><span class="pre">f(x;</span> <span class="pre">keywords...)</span></tt>,
can be slow and should be avoided in performance-sensitive code.</p>
</div>
</div>
<div class="section" id="break-functions-into-multiple-definitions">
<h2>Break functions into multiple definitions<a class="headerlink" href="#break-functions-into-multiple-definitions" title="Permalink to this headline">¶</a></h2>
<p>Writing a function as many small definitions allows the compiler to
directly call the most applicable code, or even inline it.</p>
<p>Here is an example of a “compound function” that should really be
written as multiple definitions:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="k">function</span><span class="nf"> norm</span><span class="p">(</span><span class="n">A</span><span class="p">)</span>
<span class="k">if</span> <span class="nb">isa</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">Vector</span><span class="p">)</span>
<span class="k">return</span> <span class="n">sqrt</span><span class="p">(</span><span class="n">real</span><span class="p">(</span><span class="n">dot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">x</span><span class="p">)))</span>
<span class="k">elseif</span> <span class="nb">isa</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">Matrix</span><span class="p">)</span>
<span class="k">return</span> <span class="n">max</span><span class="p">(</span><span class="n">svd</span><span class="p">(</span><span class="n">A</span><span class="p">)[</span><span class="mi">2</span><span class="p">])</span>
<span class="k">else</span>
<span class="nb">error</span><span class="p">(</span><span class="s">"norm: invalid argument"</span><span class="p">)</span>
<span class="k">end</span>
<span class="k">end</span>
</pre></div>
</div>
<p>This can be written more concisely and efficiently as:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">norm</span><span class="p">(</span><span class="n">A</span><span class="p">::</span><span class="n">Vector</span><span class="p">)</span> <span class="o">=</span> <span class="n">sqrt</span><span class="p">(</span><span class="n">real</span><span class="p">(</span><span class="n">dot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">x</span><span class="p">)))</span>
<span class="n">norm</span><span class="p">(</span><span class="n">A</span><span class="p">::</span><span class="n">Matrix</span><span class="p">)</span> <span class="o">=</span> <span class="n">max</span><span class="p">(</span><span class="n">svd</span><span class="p">(</span><span class="n">A</span><span class="p">)[</span><span class="mi">2</span><span class="p">])</span>
</pre></div>
</div>
</div>
<div class="section" id="write-type-stable-functions">
<h2>Write “type-stable” functions<a class="headerlink" href="#write-type-stable-functions" title="Permalink to this headline">¶</a></h2>
<p>When possible, it helps to ensure that a function always returns a value
of the same type. Consider the following definition:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">pos</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">=</span> <span class="n">x</span> <span class="o"><</span> <span class="mi">0</span> <span class="o">?</span> <span class="mi">0</span> <span class="p">:</span> <span class="n">x</span>
</pre></div>
</div>
<p>Although this seems innocent enough, the problem is that <tt class="docutils literal"><span class="pre">0</span></tt> is an
integer (of type <tt class="docutils literal"><span class="pre">Int</span></tt>) and <tt class="docutils literal"><span class="pre">x</span></tt> might be of any type. Thus,
depending on the value of <tt class="docutils literal"><span class="pre">x</span></tt>, this function might return a value of
either of two types. This behavior is allowed, and may be desirable in
some cases. But it can easily be fixed as follows:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">pos</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">=</span> <span class="n">x</span> <span class="o"><</span> <span class="mi">0</span> <span class="o">?</span> <span class="n">zero</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="p">:</span> <span class="n">x</span>
</pre></div>
</div>
<p>There is also a <tt class="docutils literal"><span class="pre">one</span></tt> function, and a more general <tt class="docutils literal"><span class="pre">oftype(x,y)</span></tt>
function, which returns <tt class="docutils literal"><span class="pre">y</span></tt> converted to the type of <tt class="docutils literal"><span class="pre">x</span></tt>. The first
argument to any of these functions can be either a value or a type.</p>
</div>
<div class="section" id="avoid-changing-the-type-of-a-variable">
<h2>Avoid changing the type of a variable<a class="headerlink" href="#avoid-changing-the-type-of-a-variable" title="Permalink to this headline">¶</a></h2>
<p>An analogous “type-stability” problem exists for variables used
repeatedly within a function:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="k">function</span><span class="nf"> foo</span><span class="p">()</span>
<span class="n">x</span> <span class="o">=</span> <span class="mi">1</span>
<span class="k">for</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">:</span><span class="mi">10</span>
<span class="n">x</span> <span class="o">=</span> <span class="n">x</span><span class="o">/</span><span class="n">bar</span><span class="p">()</span>
<span class="k">end</span>
<span class="k">return</span> <span class="n">x</span>
<span class="k">end</span>
</pre></div>
</div>
<p>Local variable <tt class="docutils literal"><span class="pre">x</span></tt> starts as an integer, and after one loop iteration
becomes a floating-point number (the result of the <tt class="docutils literal"><span class="pre">/</span></tt> operator). This
makes it more difficult for the compiler to optimize the body of the
loop. There are several possible fixes:</p>
<ul class="simple">
<li>Initialize <tt class="docutils literal"><span class="pre">x</span></tt> with <tt class="docutils literal"><span class="pre">x</span> <span class="pre">=</span> <span class="pre">1.0</span></tt></li>
<li>Declare the type of <tt class="docutils literal"><span class="pre">x</span></tt>: <tt class="docutils literal"><span class="pre">x::Float64</span> <span class="pre">=</span> <span class="pre">1</span></tt></li>
<li>Use an explicit conversion: <tt class="docutils literal"><span class="pre">x</span> <span class="pre">=</span> <span class="pre">one(T)</span></tt></li>
</ul>
</div>
<div class="section" id="separate-kernel-functions">
<h2>Separate kernel functions<a class="headerlink" href="#separate-kernel-functions" title="Permalink to this headline">¶</a></h2>
<p>Many functions follow a pattern of performing some set-up work, and then
running many iterations to perform a core computation. Where possible,
it is a good idea to put these core computations in separate functions.
For example, the following contrived function returns an array of a
randomly-chosen type:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="k">function</span><span class="nf"> strange_twos</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
<span class="n">a</span> <span class="o">=</span> <span class="n">Array</span><span class="p">(</span><span class="n">randbool</span><span class="p">()</span> <span class="o">?</span> <span class="kt">Int64</span> <span class="p">:</span> <span class="kt">Float64</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
<span class="k">for</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">:</span><span class="n">n</span>
<span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="mi">2</span>
<span class="k">end</span>
<span class="k">return</span> <span class="n">a</span>
<span class="k">end</span>
</pre></div>
</div>
<p>This should be written as:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="k">function</span><span class="nf"> fill_twos</span><span class="o">!</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
<span class="k">for</span> <span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">:</span><span class="n">length</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
<span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="mi">2</span>
<span class="k">end</span>
<span class="k">end</span>
<span class="k">function</span><span class="nf"> strange_twos</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
<span class="n">a</span> <span class="o">=</span> <span class="n">Array</span><span class="p">(</span><span class="n">randbool</span><span class="p">()</span> <span class="o">?</span> <span class="kt">Int64</span> <span class="p">:</span> <span class="kt">Float64</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
<span class="n">fill_twos</span><span class="o">!</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
<span class="k">return</span> <span class="n">a</span>
<span class="k">end</span>
</pre></div>
</div>
<p>Julia’s compiler specializes code for argument types at function
boundaries, so in the original implementation it does not know the type
of <tt class="docutils literal"><span class="pre">a</span></tt> during the loop (since it is chosen randomly). Therefore the
second version is generally faster since the inner loop can be
recompiled as part of <tt class="docutils literal"><span class="pre">fill_twos!</span></tt> for different types of <tt class="docutils literal"><span class="pre">a</span></tt>.</p>
<p>The second form is also often better style and can lead to more code
reuse.</p>
<p>This pattern is used in several places in the standard library. For
example, see <tt class="docutils literal"><span class="pre">hvcat_fill</span></tt> in
<a class="reference external" href="https://github.com/JuliaLang/julia/blob/master/base/abstractarray.jl">abstractarray.jl</a>,
or the <tt class="docutils literal"><span class="pre">fill!</span></tt> function, which we could have used instead of writing
our own <tt class="docutils literal"><span class="pre">fill_twos!</span></tt>.</p>
<p>Functions like <tt class="docutils literal"><span class="pre">strange_twos</span></tt> occur when dealing with data of
uncertain type, for example data loaded from an input file that might
contain either integers, floats, strings, or something else.</p>
</div>
<div class="section" id="fix-deprecation-warnings">
<h2>Fix deprecation warnings<a class="headerlink" href="#fix-deprecation-warnings" title="Permalink to this headline">¶</a></h2>
<p>A deprecated function internally performs a lookup in order to
print a relevant warning only once. This extra lookup can cause a
significant slowdown, so all uses of deprecated functions should be
modified as suggested by the warnings.</p>
</div>
<div class="section" id="tweaks">
<h2>Tweaks<a class="headerlink" href="#tweaks" title="Permalink to this headline">¶</a></h2>
<p>These are some minor points that might help in tight inner loops.</p>
<ul class="simple">
<li>Use <tt class="docutils literal"><span class="pre">size(A,n)</span></tt> when possible instead of <tt class="docutils literal"><span class="pre">size(A)</span></tt> or <tt class="docutils literal"><span class="pre">size(A)[n]</span></tt>.</li>
<li>Avoid unnecessary arrays. For example, instead of <tt class="docutils literal"><span class="pre">sum([x,y,z])</span></tt>
use <tt class="docutils literal"><span class="pre">x+y+z</span></tt>.</li>
<li>Use <tt class="docutils literal"><span class="pre">*</span></tt> instead of raising to small integer powers, for example
<tt class="docutils literal"><span class="pre">x*x*x</span></tt> instead of <tt class="docutils literal"><span class="pre">x^3</span></tt>.</li>
<li>Use <tt class="docutils literal"><span class="pre">abs2(z)</span></tt> instead of <tt class="docutils literal"><span class="pre">abs(z)^2</span></tt> for complex <tt class="docutils literal"><span class="pre">z</span></tt>. In general,
try to rewrite code to use <tt class="docutils literal"><span class="pre">abs2</span></tt> instead of <tt class="docutils literal"><span class="pre">abs</span></tt> for complex arguments.</li>
<li>Use <tt class="docutils literal"><span class="pre">div(x,y)</span></tt> for truncating division of integers instead of
<tt class="docutils literal"><span class="pre">trunc(x/y)</span></tt>, and <tt class="docutils literal"><span class="pre">fld(x,y)</span></tt> instead of <tt class="docutils literal"><span class="pre">floor(x/y)</span></tt>.</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<p class="logo">
<svg version="1.1" id="Layer_1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="158px" height="106px" viewBox="0 0 310 216" enable-background="new 0 0 310 216"
xml:space="preserve">
<!-- blue dot -->
<circle fill="#6b85dd" stroke="#4266d5" stroke-width="3" cx="50.5" cy="58.665" r="16.5"/>
<!-- red dot -->
<circle fill="#d66661" stroke="#c93d39" stroke-width="3" cx="212.459" cy="60.249" r="16.5"/>
<!-- green dot -->
<circle fill="#6bab5b" stroke="#3b972e" stroke-width="3" cx="233.834" cy="23.874" r="16.5"/>
<!-- purple dot -->
<circle fill="#aa7dc0" stroke="#945bb0" stroke-width="3" cx="255.459" cy="59.999" r="16.5"/>
<!-- "j" -->
<path fill="#252525" d="M37.216,138.427c0-15.839,0.006-31.679-0.018-47.517c-0.001-0.827,0.169-1.234,1.043-1.47
c7.876-2.127,15.739-4.308,23.606-6.47c1.33-0.366,1.333-0.36,1.333,1.019c0,25.758,0.015,51.517-0.012,77.274
c-0.006,5.514,0.245,11.032-0.272,16.543c-0.628,6.69-2.15,13.092-6.438,18.506c-3.781,4.771-8.898,7.25-14.767,8.338
c-6.599,1.222-13.251,1.552-19.934,0.938c-4.616-0.423-9.045-1.486-12.844-4.363c-2.863-2.168-4.454-4.935-3.745-8.603
c0.736-3.806,3.348-5.978,6.861-7.127c2.262-0.74,4.628-0.872,6.994-0.53c1.823,0.264,3.42,1.023,4.779,2.288
c1.38,1.284,2.641,2.674,3.778,4.177c0.872,1.15,1.793,2.256,2.991,3.086c2.055,1.426,4,0.965,5.213-1.216
c0.819-1.473,0.997-3.106,1.173-4.731c0.255-2.348,0.255-4.707,0.256-7.062C37.218,167.145,37.216,152.786,37.216,138.427z"/>
<!-- "u" -->
<path fill="#252525" d="M125.536,162.479c-2.908,2.385-5.783,4.312-8.88,5.904c-10.348,5.323-20.514,4.521-30.324-1.253
c-6.71-3.95-11.012-9.849-12.52-17.606c-0.236-1.213-0.363-2.438-0.363-3.688c0.01-19.797,0.017-39.593-0.02-59.39
c-0.002-1.102,0.285-1.357,1.363-1.351c7.798,0.049,15.597,0.044,23.396,0.003c0.95-0.005,1.177,0.25,1.175,1.183
c-0.027,19.356-0.025,38.713-0.018,58.07c0.002,6.34,3.599,10.934,9.672,12.42c2.13,0.521,4.19,0.396,6.173-0.6
c4.26-2.139,7.457-5.427,10.116-9.307c0.333-0.487,0.224-1,0.224-1.51c0.007-19.635,0.016-39.271-0.02-58.904
c-0.002-1.083,0.255-1.369,1.353-1.361c7.838,0.052,15.677,0.045,23.515,0.004c0.916-0.005,1.103,0.244,1.102,1.124
c-0.025,27.677-0.026,55.353,0.002,83.024c0.001,0.938-0.278,1.099-1.139,1.095c-7.918-0.028-15.837-0.028-23.756-0.001
c-0.815,0.003-1.1-0.166-1.073-1.037C125.581,167.117,125.536,164.928,125.536,162.479z"/>
<!-- "l" -->
<path fill="#252525" d="M187.423,107.08c0,20.637-0.011,41.273,0.026,61.91c0.003,1.119-0.309,1.361-1.381,1.355
c-7.799-0.052-15.598-0.047-23.396-0.008c-0.898,0.008-1.117-0.222-1.115-1.115c0.021-39.074,0.021-78.147,0-117.226
c0-0.811,0.189-1.169,1.006-1.392c7.871-2.149,15.73-4.327,23.584-6.545c1.045-0.295,1.308-0.17,1.306,0.985
C187.412,65.727,187.423,86.403,187.423,107.08z"/>
<!-- "i" -->
<path fill="#252525" d="M223.46,126.477c0,14.155-0.011,28.312,0.021,42.467c0.002,1.027-0.164,1.418-1.332,1.408
c-7.838-0.061-15.676-0.047-23.516-0.01c-0.881,0.004-1.121-0.189-1.119-1.104c0.026-26.153,0.025-52.307,0-78.458
c0-0.776,0.203-1.101,0.941-1.302c7.984-2.172,15.972-4.35,23.938-6.596c1.049-0.296,1.08,0.031,1.078,0.886
C223.454,98.004,223.46,112.239,223.46,126.477z"/>
<!-- "a" -->
<path fill="#252525" d="M277.695,163.6c-0.786,0.646-1.404,1.125-2,1.635c-4.375,3.746-9.42,5.898-15.16,6.42
c-5.792,0.527-11.479,0.244-16.934-2.047c-12.08-5.071-15.554-17.188-11.938-27.448c1.799-5.111,5.472-8.868,9.831-11.94
c5.681-4.003,12.009-6.732,18.504-9.074c5.576-2.014,11.186-3.939,16.955-5.347c0.445-0.104,0.773-0.243,0.757-0.854
c-0.136-4.389,0.261-8.79-0.479-13.165c-1.225-7.209-6.617-10.013-12.895-9.348c-0.516,0.055-1.029,0.129-1.536,0.241
c-4.877,1.081-7.312,4.413-7.374,10.127c-0.02,1.729-0.229,3.418-0.693,5.084c-0.906,3.229-2.969,5.354-6.168,6.266
c-3.422,0.979-6.893,0.998-10.23-0.305c-6.529-2.543-8.877-10.164-5.12-16.512c2.249-3.799,5.606-6.4,9.461-8.405
c6.238-3.246,12.914-4.974,19.896-5.537c7.565-0.61,15.096-0.366,22.49,1.507c4.285,1.085,8.312,2.776,11.744,5.657
c4.473,3.749,6.776,8.647,6.812,14.374c0.139,21.477,0.096,42.951,0.143,64.428c0.002,0.799-0.248,0.983-1.021,0.98
c-8.035-0.025-16.074-0.023-24.113-0.001c-0.716,0.002-0.973-0.146-0.941-0.915C277.736,167.562,277.695,165.698,277.695,163.6z
M277.695,126.393c-4.793,2.104-9.25,4.373-13.287,7.408c-2.151,1.618-4.033,3.483-5.732,5.581
c-4.229,5.226-1.988,13.343,1.693,16.599c1.592,1.406,3.359,1.906,5.419,1.521c1.621-0.307,3.149-0.857,4.549-1.734
c1.521-0.951,2.949-2.072,4.539-2.887c2.31-1.18,2.97-2.861,2.894-5.445C277.561,140.484,277.695,133.527,277.695,126.393z"/>
</svg>
</p>
<h3><a href="../index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Performance Tips</a><ul>
<li><a class="reference internal" href="#avoid-global-variables">Avoid global variables</a></li>
<li><a class="reference internal" href="#avoid-containers-with-abstract-type-parameters">Avoid containers with abstract type parameters</a></li>
<li><a class="reference internal" href="#type-declarations">Type declarations</a><ul>
<li><a class="reference internal" href="#declare-specific-types-for-fields-of-composite-types">Declare specific types for fields of composite types</a></li>
<li><a class="reference internal" href="#annotate-values-taken-from-untyped-locations">Annotate values taken from untyped locations</a></li>
<li><a class="reference internal" href="#declare-types-of-keyword-arguments">Declare types of keyword arguments</a></li>
</ul>
</li>
<li><a class="reference internal" href="#break-functions-into-multiple-definitions">Break functions into multiple definitions</a></li>
<li><a class="reference internal" href="#write-type-stable-functions">Write “type-stable” functions</a></li>
<li><a class="reference internal" href="#avoid-changing-the-type-of-a-variable">Avoid changing the type of a variable</a></li>
<li><a class="reference internal" href="#separate-kernel-functions">Separate kernel functions</a></li>
<li><a class="reference internal" href="#fix-deprecation-warnings">Fix deprecation warnings</a></li>
<li><a class="reference internal" href="#tweaks">Tweaks</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="packages.html"
title="previous chapter">Packages</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="style-guide.html"
title="next chapter">Style Guide</a></p>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="../search.html" method="get">
<table><tr><td>
<input type="text" name="q" /><input type="submit" value="Go" />
<!--<input type="hidden" name="check_keywords" value="yes" />-->
<!--<input type="hidden" name="area" value="default" />-->
</td></tr></table>
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footerwrapper">
<div class="footer">
<div class="prevlink">
<a href="packages.html">« Packages</a>
</div>
<div class="nextlink">
<a href="style-guide.html">Style Guide »</a>
</div>
</div>
</div>
</body>
</html>
|