Optimisation fence [closed]

Solution 1:

Probably a better question for StackOverflow.

Roughly... when code optimization tools are pointed at a program, they break it down into smaller parts at particular boundaries, and optimize each separately. There might be that there are further improvements that could be made if the program as a whole were to be considered, but the optimizer is not capable of seeing these because it's considering each small part individually. The boundaries at which a program must be broken up before optimization are considered optimization fences.

Consider the following pseudo-code:

var $x;

function foo () {
  $x = $x + 1;
}

function bar () {
  $x = $x + 1;
  $x = $x + 1;
}

function foobar () {
  foo();
  bar();
}

If functions are an optimization fence, then the optimizer might be able to optimize bar to:

function bar () {
  $x = $x + 2;
}

But would not be able to optimize foobar to:

function foobar () {
  $x = $x + 3;
}

In practice, function definitions are often not an optimization fence - most decent optimizers are able to cross them by "inlining" smaller functions into larger ones when it is likely to improve performance. More likely fences include things that affect global state (e.g. global variables, and input/output).

Solution 2:

To put it simply, it refers to the boundary (limit) of optimising something. It is generally defined by a graph showing the shape of optimisation, used in mathematical and statistical issues.

https://math.stackexchange.com/questions/448485/classic-optimization-fence-problem

Solution 3:

This is also a technical term from the domain of database administration and a better answer may be found by posting your question in that forum. This related question has been asked there.

But generally, in database queries there may be certain in-line functions or views which are not able to participate in query optimization for different reasons. For example, a function may be written in a different query language or data in views may be remote to the main query. If the function or view is not able to participate in query optimization then it is said to exist within an optimization fence.