Questions about how to optimise a program's performance, both manually and automatically, e.g. in compilers.
Questions tagged [program-optimization]
91 questions
24
votes
2 answers
Why is static-single assignment preferred over continuation passing style in many industry-used compilers?
According to the Wikipedia page on static-single assignment (SSA), SSA is used by large and well-known projects such as LLVM, GCC, MSVC, Mono, Dalvik, SpiderMonkey, and V8 while the page on projects using continuation-passing style (CPS) is a bit…
CinchBlue
- 614
- 4
- 16
22
votes
12 answers
Data structure or algorithm for quickly finding differences between strings
I have an array of 100,000 strings, all of length $k$. I want to compare each string to every other string to see if any two strings differ by 1 character. Right now, as I add each string to the array, I'm checking it against every string already…
JGut
- 331
- 1
- 2
- 6
22
votes
4 answers
Automated optimization of 0-1 matrix vector multiplication
Question:
Is there established procedure or theory for generating code that efficiently applies a matrix-vector multiplication, when the matrix is dense and filled with only zeros and ones? Ideally, the optimized code would make systematic use of…
Nick Alger
- 1,049
- 7
- 18
20
votes
1 answer
Do fully optimizing compilers for terminating programs exist?
In Andrew W. Appel's book, Modern Compiler Implementation in ML, he says under chapter 17 that Computability theory shows that it will always be possible to invent new optimizing transformations and proceeds to prove that a fully optimizing compiler…
sshine
- 519
- 3
- 17
16
votes
2 answers
What property of cons allows elimination of tail recursion modulo cons?
I'm familiar with the idea of basic tail recursion elimination, where functions that return the direct result of a call to themselves can be rewritten as iterative loops.
foo(...):
# ...
return foo(...)
I also understand that, as a special…
Maxpm
- 263
- 1
- 7
11
votes
3 answers
Equivalence of data-flow analysis, abstract interpretation and type inference?
@Babou's answer to a recent question reminds me that at one time I think I read a paper about the equivalence (in terms both of the facts that can be inferred or proved and the time complexity of running the inference algorithm) of data-flow…
Wandering Logic
- 17,863
- 1
- 46
- 87
11
votes
5 answers
Why is the OS design able to reduce power consumption?
I have read that OSes like Android and iOS are somehow optimised to improve battery life.
My understanding is that a CPU executes a certain number of operations in a certain time, so I would think that you can speed up applications by reducing…
neelsg
- 221
- 1
- 7
10
votes
1 answer
Micro-optimisation for edit distance computation: is it valid?
On Wikipedia, an implementation for the bottom-up dynamic programming scheme for the edit distance is given. It does not follow the definition completely; inner cells are computed thus:
if s[i] = t[j] then
d[i, j] := d[i-1, j-1] // no…
Raphael
- 73,212
- 30
- 182
- 400
10
votes
1 answer
What is the name of this type of program optimization where two loops operating over common data are combined into a single loop?
On an imperative programming language, let us consider the following program:
for i in 0..N { // N is the length of the arrays A, B, C.
A[i] = A[i] + B[i];
}
for i in 0..N {
A[i] = A[i] + C[i];
}
This program just sums three arrays $A + B + C$…
yuezato
- 123
- 7
8
votes
3 answers
Constant folding vs. Constant propogation
What is the difference between constant folding and constant propogation? They both seem to do the same thing, instead of saving constants into stack or evaluating a full arithmetic expression, they simply replace it with the result which can be…
nikolaevra
- 323
- 3
- 7
8
votes
1 answer
Data Flow Analysis with exceptions
Data flow analysis work over a control flow graph. When a language under consideration supports exceptions, control flow graph can explode.
What are the standard techniques for dealing with this blow-up?
Can we soundly disregard edges induced by…
zpavlinovic
- 1,664
- 10
- 19
8
votes
0 answers
Optimizing order of graph reduction to minimize memory usage
Having extracted the data-flow in some rather large programs as directed, acyclic graphs, I'd now like to optimize the order of evaluation to minimze the maximum amount of memory used.
That is, given a graph {1 -> 3, 2 -> 3, 4 -> 5, 3 -> 5}, I'm…
Baughn
- 81
- 1
7
votes
2 answers
generating pi using Machin like formula
Back in 2002, using this arctan formula for pi discoverd by Stoemer:
$$ \pi = 176 \arctan(1/57) + 28 \arctan(1/239) - 48 \arctan(1/682) \\ +
96 \arctan(1/12943)$$
and I assume using this series for arctan:
$$ \arctan(x) = x - \frac{x^3}{3} +…
rcgldr
- 364
- 2
- 12
7
votes
1 answer
Reference request: optimizing procedures on lists in dynamic languages by performing safety checks in advance
For my science fair project, I implemented an optimization to Python's sort routine. The idea is to move the safety checks that have to be carried out during each comparison, e.g. type checks and character-width checks, outside of the sort loop and…
Elliot Gorokhovsky
- 923
- 4
- 15
7
votes
1 answer
When is it useful to split critical edges?
Some compilers have utility functions that split critical edges in the control flow graph. I assume that this is not done as an optimization in itself, but rather to simplify other analyses and transformations. In what cases would splitting critical…
zr.
- 171
- 2