Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Program optimization
(section)
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!
==Automated and manual optimization== {{Main|Optimizing compiler}} ''See also [[:Category:Compiler optimizations]]'' Optimization can be automated by compilers or performed by programmers. Gains are usually limited for local optimization, and larger for global optimizations. Usually, the most powerful optimization is to find a superior [[algorithm]]. Optimizing a whole system is usually undertaken by programmers because it is too complex for automated optimizers. In this situation, programmers or [[system administrator]]s explicitly change code so that the overall system performs better. Although it can produce better efficiency, it is far more expensive than automated optimizations. Since many parameters influence the program performance, the program optimization space is large. Meta-heuristics and machine learning are used to address the complexity of program optimization.<ref>{{cite journal|last1=Memeti|first1=Suejb|last2=Pllana|first2=Sabri|last3=Binotto|first3=Alécio|last4=Kołodziej|first4=Joanna|last5=Brandic|author5-link= Ivona Brandić |first5=Ivona|title=Using meta-heuristics and machine learning for software optimization of parallel computing systems: a systematic literature review|journal=Computing|volume=101|issue=8|pages=893–936|date=26 April 2018|doi=10.1007/s00607-018-0614-9|publisher=Springer Vienna|arxiv=1801.09444|bibcode=2018arXiv180109444M|s2cid=13868111}}</ref> Use a [[Profiler (computer science)|profiler]] (or [[Profiling (computer programming)|performance analyzer]]) to find the sections of the program that are taking the most resources{{snd}} the ''bottleneck''. Programmers sometimes believe they have a clear idea of where the bottleneck is, but intuition is frequently wrong.{{citation needed|date=May 2012}} Optimizing an unimportant piece of code will typically do little to help the overall performance. When the bottleneck is localized, optimization usually starts with a rethinking of the algorithm used in the program. More often than not, a particular algorithm can be specifically tailored to a particular problem, yielding better performance than a generic algorithm. For example, the task of sorting a huge list of items is usually done with a [[quicksort]] routine, which is one of the most efficient generic algorithms. But if some characteristic of the items is exploitable (for example, they are already arranged in some particular order), a different method can be used, or even a custom-made sort routine. After the programmer is reasonably sure that the best algorithm is selected, code optimization can start. Loops can be unrolled (for lower loop overhead, although this can often lead to ''lower'' speed if it overloads the [[CPU cache]]), data types as small as possible can be used, integer arithmetic can be used instead of floating-point, and so on. (See [[algorithmic efficiency]] article for these and other techniques.) Performance bottlenecks can be due to language limitations rather than algorithms or data structures used in the program. Sometimes, a critical part of the program can be re-written in a different [[programming language]] that gives more direct access to the underlying machine. For example, it is common for very [[High-level programming language|high-level]] languages like [[Python (programming language)|Python]] to have modules written in [[C (programming language)|C]] for greater speed. Programs already written in C can have modules written in [[assembly language|assembly]]. Programs written in [[D programming language|D]] can use the [[inline assembler]]. Rewriting sections "pays off" in these circumstances because of a general "[[rule of thumb]]" known as the 90/10 law, which states that 90% of the time is spent in 10% of the code, and only 10% of the time in the remaining 90% of the code. So, putting intellectual effort into optimizing just a small part of the program can have a huge effect on the overall speed{{snd}} if the correct part(s) can be located. Manual optimization sometimes has the side effect of undermining readability. Thus code optimizations should be carefully documented (preferably using in-line comments), and their effect on future development evaluated. The program that performs an automated optimization is called an '''optimizer'''. Most optimizers are embedded in compilers and operate during compilation. Optimizers can often tailor the generated code to specific processors. Today, automated optimizations are almost exclusively limited to [[compiler optimization]]. However, because compiler optimizations are usually limited to a fixed set of rather general optimizations, there is considerable demand for optimizers which can accept descriptions of problem and language-specific optimizations, allowing an engineer to specify custom optimizations. Tools that accept descriptions of optimizations are called [[program transformation]] systems and are beginning to be applied to real software systems such as C++. Some high-level languages ([[Eiffel (programming language)|Eiffel]], [[Esterel]]) optimize their programs by using an [[intermediate language]]. [[Grid computing]] or [[distributed computing]] aims to optimize the whole system, by moving tasks from computers with high usage to computers with idle time.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)