Questions tagged [optimization]
Use this tag for questions about efficient compilation or execution of a programming language, including in a virtual machine, or language features that facilitate more efficient code generation or execution for interpreters
44 questions
5
votes
0
answers
152
views
What efficient heuristics exist for factoring distributive operations?
Some operations are distributive over each other. (addition/multiplication, and/or, etc) That property can be used to optimize code with factoring.
However, optimal factoring can be quite slow in the ...
13
votes
6
answers
8k
views
Why do so few source level optimizers exist?
Why do optimizing compilers never offer backends in the source language itself? Isn't targeting the source language much easier than targeting assembly? Also, couldn't a source-to-source optimizer ...
8
votes
0
answers
162
views
Non-trivial implementations of consume memory ordering
In the C++ memory model through C++23, one of the memory ordering types for loads is memory_order_consume. The intent of this was to expose the feature that most ...
6
votes
1
answer
268
views
Why doesn't lazy basic block versioning use type sets?
In Simple and Effective Type Check Removal
through Lazy Basic Block Versioning, which introduces Lazy Basic Block Versioning (LBBV), they have runtime type checks expand into two thunks for the cases ...
6
votes
0
answers
331
views
What challenges might still prevent compiler or JIT optimizations of common FP operations like map, filter, and reduce?
(While I'm referring to JS in my example, I don't intend to be constrained to JS: so any comments/answers concerning FP-style APIs for working with collections for any language are welcome and ...
6
votes
3
answers
626
views
What design choices inform whether a whole-program optimizing compiler is possible?
What design restrictions inform a language having / having a useful whole-program optimizing compiler?
I'm aware that Standard ML has a whole-program optimizing compiler implementation in MLton. I ...
50
votes
5
answers
18k
views
What are the ways compilers recognize complex patterns?
This answer is an example of a compiler recognizing that a complex expression is equivalent to a single operation:
...
1
vote
0
answers
206
views
How can transpilers benefit from compiler optimizations which are compatible with semantics, if other "optimizations" in the target language aren't?
Consider the following function:
...
0
votes
4
answers
713
views
How to design a programming language that can simplify/optimize algorithms?
Can I design or implement a programming language (doesn't have to be general purpose) such that "suboptimal" code in the language will become optimal after compilation?
E.g., guaranteeing ...
5
votes
1
answer
728
views
How does link-time function inlining work?
I am familiar with traditional linking concepts (static and dynamic linking, relocation, PIE) and with traditional compiler optimizations (such as static expression evaluation, loop unrolling and ...
3
votes
6
answers
644
views
Are there languages or compilers having optimizations to deallocate variables early?
In a scope that defines two variables a and b, the code firstly does things only on a. Then <...
12
votes
0
answers
325
views
How can a compiler optimise persistent data structures to use mutable data structures "under the hood"?
Consider for a motivating example a copy-on-write array, which implements a persistent (i.e. immutable) array data type. As an optimisation at runtime, a reference counter can be used to avoid the ...
0
votes
1
answer
214
views
How to minimize total size of static data?
I am implementing a WASM backend and I hope to optimize the size.
I have collected a series of static data. After erasing the type, it can be simply
considered as ...
3
votes
1
answer
610
views
How to assign unique names to variables within a function?
I want to promote all variables within the function to the top level of the function, make it more cache-friendly and reduce size bloat caused by alignment fill.
In other words, it will roughly ...
3
votes
2
answers
692
views
Pros and cons of treating endless loops as "anything can happen" UB, versus merely allowing limited reordering
Many programming languages, including C89, specify that the behavior of a program in terms of sequentially executed steps, whose behavior is in turn defined in terms of the program's state when the ...