Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Optimizing compiler
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Other optimizations === ;[[Bounds-checking elimination]]: Many languages, such as [[Java (programming language)|Java]], enforce [[bounds checking]] of all array accesses. This is a severe performance [[Bottleneck (software)|bottleneck]] on certain applications such as scientific code. Bounds-checking elimination allows the compiler to safely remove bounds checking in many situations where it can determine that the index must fall within valid bounds; for example, if it is a simple loop variable. ;Branch-offset optimization (machine dependent): Choose the shortest branch displacement that reaches the target. ;Code-block reordering: Code-block reordering alters the order of the basic [[Block (programming)|blocks]] in a program to reduce conditional branches and improve the locality of reference. ;[[Dead-code elimination]]: Removes instructions that will not affect the behaviour of the program, for example, definitions that have no uses, called [[dead code]]. This reduces code size and eliminates unnecessary computation. ;Factoring out of invariants ([[loop invariant]]s): If an expression is carried out both when a condition is met and is not met, it can be written just once outside of the conditional statement. Similarly, if certain types of expressions (e.g., the assignment of a constant into a variable) appear inside a loop, they can be moved out of it because their effect will be the same no matter if they're executed many times or just once. This is also known as total redundancy elimination. A similar but more powerful optimization is [[partial-redundancy elimination]] (PRE). ;[[Inline expansion]] or [[Macro (computer science)|macro]] expansion: When some code invokes a [[Subroutine|procedure]], it is possible to directly insert the body of the procedure inside the calling code rather than transferring control to it. This saves the overhead related to procedure calls, as well as providing an opportunity for many different parameter-specific optimizations, but comes at the cost of space; the procedure body is duplicated each time the procedure is called inline. Generally, inlining is useful in performance-critical code that makes a large number of calls to small procedures. This is a "fewer jumps" optimization. The [[Statement (computer science)|statements]] of [[imperative programming]] languages are also an example of such an optimization. Although statements could be implemented with [[subroutine|function calls]] they are almost always implemented with code inlining. ;[[Jump threading]]: In this optimization, consecutive conditional jumps predicated entirely or partially on the same condition are merged. : E.g., {{c-lang|if (c) { foo; } if (c) {{(}} bar; {{)}}}} to {{c-lang|if (c) {{(}} foo; bar; {{)}}}}, :and {{c-lang|if (c) { foo; } if (!c) {{(}} bar; {{)}}}} to {{c-lang|if (c) { foo; } else {{(}} bar; {{)}}}}. ;Macro compression: A space optimization that recognizes common sequences of code, creates subprograms ("code macros") that contain the common code, and replaces the occurrences of the common code sequences with calls to the corresponding subprograms.<ref name="MCO"/> This is most effectively done as a [[machine code]] optimization, when all the code is present. The technique was first used to conserve space in an interpretive [[byte stream]] used in an implementation of [[SPITBOL compiler|Macro Spitbol]] on [[microcomputers]].<ref name="MicroSpitbol"> {{cite book|last1=Dewar|first1=Robert B. K.|author-link1=Robert Dewar|title=MICRO SPITBOL|last2=Golumbic|first2=Martin Charles|author-link2=Martin Charles Golumbic|last3=Goss|first3=Clinton F.|date=August 2013|publisher=Courant Institute of Mathematical Sciences|series=Computer Science Department Technical Report|volume=11|bibcode=2013arXiv1308.6096D|orig-date=October 1979|arxiv=1308.6096}} </ref> The problem of determining an optimal set of macros that minimizes the space required by a given code segment is known to be [[NP-complete]],<ref name="MCO"/> but efficient heuristics attain near-optimal results.<ref>{{cite conference|last1=Golumbic|first1=Martin Charles|author-link1=Martin Charles Golumbic|last2=Dewar|first2=Robert B. K.|author-link2=Robert Dewar|last3=Goss|first3=Clinton F.|year=1980|title=Macro Substitutions in MICRO SPITBOL β a Combinatorial Analysis|conference=11th Southeastern Conference on Combinatorics, Graph Theory and Computing|volume=29|pages=485β495|book-title=Proceedings of the 11th Southeastern Conference on Combinatorics, Graph Theory and Computing, Congressus Numerantium, Utilitas Math., Winnipeg, Canada}}</ref> ;Reduction of [[cache (computing)|cache]] collisions: (e.g., by disrupting alignment within a page) ;[[Call stack|Stack]]-height reduction: Rearrange an expression tree to minimize resources needed for expression evaluation.{{Clarify|date=December 2023|reason=On a [[stack machine]], it can reduce the depth of the evaluation stack, but not all machines use an evaluation stack - this might, for example, reduce register usage and thus register pressure.}} ;Test reordering: If we have two tests that are the condition for something, we can first deal with the simpler tests (e.g., comparing a variable to something) and only then with the complex tests (e.g., those that require a function call). This technique complements [[lazy evaluation]], but can be used only when the tests are not dependent on one another. [[Minimal evaluation|Short-circuiting]] semantics can make this difficult.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Optimizing compiler
(section)
Add topic