Redundancy Elimination

Property settings

This optimization is turned OFF by default.
In the property file,
OPT.VN=ON turns on this optimization
OPT.VN=OFF turns off this optimization

Redundancy Elimination removes expressions that have multiple occurrences in a method. By removing duplicate expressions Redundancy Elimination will increase the performance and may reduce the size of the application. It is important to point out that field reading and array loading are computationally expensive, and these could be automatically removed by mBooster.

Redundancy Elimination is able to remove redundant

  • Arithmetic expressions
  • Field reads
  • Array loads
Original code
void someMethod() {
    int x = ...
    int y = ...
    int z = (x+y);
    doSomeCalculation(x+y);

    Player player = ...;
    NonPlayerCharacter assassin = ...;
    Weapon knife = ...;
    if (assassin.power > 0) {
        player.doDamage(assassin.power * knife.power);
    } 
    int[] intArray = ...
    for (int i = 0; i < intArray.length; i++) {
        intArray[i] = ....
        doSomething(intArray[i]);
        doSomethingElse(intArray[i]);
    }
}

When Redundancy Elimination is turned on and it is determined that the replacement is cost effective, mBooster optimizes the above code fragment to the following equivalent code, with the following replacements:

  • x+y is now replaced by z
  • assassin.power is replaced by a new local variable assassinPower
  • intArray[i] is replaced by a new local variable elementValue
Equivalent optimized code
void someMethod() {
    int x = ...
    int y = ...
    int z = (x+y);
    doSomeCalculation(z);

    Player player = ...;
    NonPlayerCharacter assassin = ...;
    Weapon knife = ...;
    int assassinPower = assassin.power;
    if (assassinPower > 0) {
        player.doDamage(assassinPower * knife.power);
    }
  
    int[] intArray = ...
    for (int i = 0; i < intArray.length; i++) {
        int elementValue = ...
        intArray[i] = elementValue;
        doSomething(elementValue);
        doSomethingElse(elementValue);
    }
}
Be Careful
  • Redundancy elimination is currently turned OFF by default.
  • The current version of Redundancy Elimination is by design very conservative. Redundancy Elimination will be considerably extended in the future.
  • Under some conditions, turning on Redundancy Elimination will increase the compressed code size, though it will offer performance advantages.
Tips
  • Turn on Redundancy Elimination if there are many repeated expressions in your application, and performance is important.
  • Manually removing redundanies is generally not advisable, as it could significantly reduce the readability of the source code.

Previous pageContentsNext page