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

Filter by
Sorted by
Tagged with
2 votes
1 answer
146 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 ...
Aster's user avatar
  • 2,552
-2 votes
1 answer
126 views

Low effort, high impact optimizations? [closed]

The Pareto principle tells us that 20% of our efforts will bring us 80% of the results. The same should be true of optimizations. Are there optimization techniques out there that: Are simple and easy ...
Matheus Moreira's user avatar
1 vote
0 answers
185 views

Pros and cons of treating endless loops as "anything can happen" UB, versus 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 ...
supercat's user avatar
  • 1,560
4 votes
0 answers
117 views

Determining the most optimized date type for the platform with type inference

For my programming language, I have built an engine that goes after the parser and before the compiler. This engine analyzes, validates, and simplifies the AST. During the analasys, it determines as ...
Hg0428's user avatar
  • 171
-1 votes
0 answers
64 views

In C, which approach is preferable: modifying a pointer's address within a void function or assigning the mutated pointer through its return value? [closed]

I have two conflicting theories regarding the optimal approach when passing the address of a pointer, particularly within a function like insert_front for a linked list. I seek insights based on ...
Pierre Ollivier's user avatar
5 votes
1 answer
183 views

Optimization algorithm using conditional invariants

I am looking for an optimization algorithm that would make use of invariants in regions of code. For example if (n == 0) f(n); should be changed to ...
chrysante's user avatar
  • 628
10 votes
1 answer
431 views

Towards a better default listlike datastructure for functional languages

In most functional languages I know of, linked lists are the default datastructure of choice for many operations. The benefits are clear - they're clearly encoded with ADTs, and can be utilised easily ...
blueberry's user avatar
  • 1,582
6 votes
2 answers
183 views

How to ensure coherent choices of representatives in an e-graph?

E-graphs are a neat intermediate representation for program transformations and optimisations, which group program terms into equivalence classes (e-classes). An optimising compiler can then select ...
kaya3's user avatar
  • 16.3k
8 votes
1 answer
502 views

What are the tradeoffs between using sea of nodes, CFG of basic blocks, and egraphs for compiler optimizations?

I've heard of "sea of nodes" intermediate representations mostly in the context of just-in-time compilation (JVM, V8, Graal) whereas intermediate representations such as LLVM IR are used in ...
Troy Sargent's user avatar
34 votes
6 answers
4k views

How to ensure that an optimising compiler will terminate?

An optimising compiler typically applies some set of rewrites to some intermediate representation of the program, replacing terms with other terms which are supposed to be equivalent but more ...
kaya3's user avatar
  • 16.3k
4 votes
1 answer
217 views

Can analysis of periodic loop behaviour be generalised to unstructured control flow?

The basic form of a loop is as follows: loopvars := init body: loopvars := f(loopvars) done := term(loopvars) br done, end, body end: Suppose we've recognised ...
Moonchild's user avatar
  • 717
5 votes
2 answers
235 views

Why would external iteration require lots of code inlining relative to internal iteration?

In Graydon Hoare's blogpost The Rust I Wanted Had No Future, they state that: Iteration used to be by stack / non-escaping coroutines, which we also called "interior" iteration, as opposed ...
JennyJams's user avatar
  • 649
6 votes
2 answers
658 views

Empirically, what are the implementation-complexity and performance implications of "unboxed" primitives?

I'm designing a Python-like language: bytecode-compiled, brace-free syntax, reference semantics for variables. Among many differences from Python, I want to support a limited form of static typing. I ...
Karl Knechtel's user avatar
24 votes
4 answers
3k views

Pros and cons of "anything-can-happen" UB versus allowing particular deviations from sequential program execution

Some language specifications invite compilers to make certain assumptions, and behave in completely arbitrary fashion if such functions are violated, even if the code in question would have ...
supercat's user avatar
  • 1,560
6 votes
2 answers
314 views

How to optimize non-tail recursion?

Tail recursion, where a function calls itself as the last step, is straightforward to optimize as to prevent unbounded stack growth: tail call optimization applies. However, this doesn't apply to ...
Bbrk24's user avatar
  • 8,553
4 votes
0 answers
178 views

Why has there been little recent work on GPU compiler phase optimization?

While GPU compiler phase optimization has been shown to improve performance significantly (e.g. https://link.springer.com/chapter/10.1007/978-3-319-75178-8_35), there has been very little follow-up ...
Amrit Baveja's user avatar
8 votes
3 answers
542 views

Tail-recursive detection and conversion

Motivation I have implemented the tail recursion optimization for my language, where a return statement calls itself by goto ...
Aster's user avatar
  • 2,552
-4 votes
1 answer
211 views

What are the disadvantages of including foreach loops? [duplicate]

Yes, FOR loops. Those great things. There are good for shortening code. But there may be downsides I'm not aware of. I'm referring to Python style FOR loops. So, what are the disadvantages of ...
Starship - On Strike's user avatar
5 votes
1 answer
159 views

Automatic copy to move promotion

I'm designing a language that has move semantics similar to C++. To make it more efficient and to prevent the need for explicit moves I want to automatically promote copies to moves if the compiler ...
chrysante's user avatar
  • 628
16 votes
7 answers
2k views

What are the pitfalls of using an existing IR/compiler infrastructure like LLVM?

Using something like LLVM when designing a compiler has a lot of advantages, since tons of work can be saved by using an existing optimizer and code generation for a variety of platforms. Even large, ...
Rydwolf Programs's user avatar
14 votes
0 answers
359 views

What is the relationship between STG and RVSDG?

GHC is an optimizing Haskell compiler. Since Haskell is lazy and mutation is rare, control flow and data flow are often very closely aligned. Therefore, it is often most useful to think about ...
Alexis King's user avatar
  • 7,779
4 votes
3 answers
548 views

What are some common ways to optimise an interpreter?

Optimization is getting things to work faster with less resources. What are some ways to optimize an interpreter?
Starship - On Strike's user avatar
2 votes
3 answers
166 views

What are the downsides, if any, of using implicit function purity in an impure language?

An idea I had for one of my languages recently was this: function purity makes it easier to do certain optimizations. However, the language I'm designing is an impure imperative language that has an ...
Seggan's user avatar
  • 2,594
2 votes
2 answers
157 views

What are the disadvantages of automatically inlining all functions?

Function inlining is when the function called is directly substituted in the calling code. This avoids the overhead of setting up the call stack, managing any relevant pointers that need to be tracked ...
FireTheLost's user avatar
  • 1,553
4 votes
2 answers
139 views

How to estimate which parts of a program will be slow?

Many modern compilers are sophisticated enough to determine that some functions or expressions can be computed lazily, memoised, or parallelised. For example, pure functions can be computed at any ...
kaya3's user avatar
  • 16.3k
8 votes
1 answer
162 views

Syntax options for providing branch prediction information

Branch prediction information can affect performance. Languages to provide programmers with ways to provide branch prediction hints to improve performance of code. One option is C++ ...
user16217248's user avatar
  • 7,245
5 votes
2 answers
713 views

Why was C implemented with a register preservation convention that seems to be far less efficient than its predecessor's?

In original implementations of the B language, the caller was responsible for saving and restoring any registers it cares about before calling a function. But in the C language, the called function is ...
Ray Butterworth's user avatar
6 votes
2 answers
272 views

Are there any disadvangates to requiring sincos() type functions?

sincos() is just a way to compute sin() and cos() at once, possibly at improved performance ...
user16217248's user avatar
  • 7,245
7 votes
2 answers
218 views

How to implement dynamic scoping?

How to implement dynamic scoping? Dynamic scoping is useful for forms of dependency injection, error handling and alternatives to thread local storage. Some examples of dynamic scoping include React's ...
Molly Stewart-Gallus's user avatar
5 votes
1 answer
132 views

Which functions should a compiler cache outputs for?

Because a bare function object might not have constant time complexity, and because the function object might be called with the same argument repeatedly, I thought it might be good to cache its ...
Dannyu NDos's user avatar
4 votes
1 answer
189 views

Implementing a number to string semantics efficiently in a C-style language?

In C our options for converting numbers to strings and adding them to a string are limited to: Write your own function. sprintf() to a buffer. Either way, one ...
user16217248's user avatar
  • 7,245
12 votes
2 answers
325 views

Which calling convention should my compiler use?

The LLVM-IR Reference Manual's section on Calling Conventions lists as many as 15 supported calling conventions. These vary in ways including whether they support tail call optimization, how many and ...
Rydwolf Programs's user avatar
13 votes
7 answers
710 views

How can a programming language support vectorization portably?

C and C++ have no vector types or operations but many compilers offer their own non-portable extensions such as __attribute__((__ext_vector_type__())). The issue is ...
user16217248's user avatar
  • 7,245