High-level Optimization for .NET Applications. Delivered

Eazfuscator.NET always takes care about the performance of your applications since the very beginning. I often find myself thinking about some exotic code transformation for the sake of better code protection and a few days later I decide to not go into it.

The reasoning behind is simple: even the most exotic code transformation is decompilable by its nature. At the same time, such kind of protection would kill the speed of your application. .NET JIT optimizer ceases when it sees the over-scrambled code, your application gets a significant slowdown as the result. A lot of obfuscators around are caught by this trap – they sell a not-so-good protection in expense of precious speed.

And now is the time when Eazfuscator.NET sets up the trend. Again.

The new version of Eazfuscator.NET applies code optimizations to deliver the best performance to your applications. .NET compilers such as C#, VB.NET, F# and JIT already do a pretty decent job in this area. But what they all don’t do is high-level optimizations.

High-level optimization is a fresh trend in optimization technology and Eazfuscator.NET establishes itself as the first tool to deliver this technology to the wide .NET user base. The best way to briefly describe high-level optimization is to start thinking as developer thinks: we all know that there are some methods and code patterns which are faster than others.

What Eazfuscator.NET does is this: it finds the slow code and swaps it with faster one. Eazfuscator.NET uses a preciously brewed knowledge base of common and efficient code patterns that you can meet in every .NET application.

At first glance, high-level optimization is very similar to a well-known peephole optimization approach. But the main difference is that the classical peephole optimization works only on a small window of target machine instructions, while high-level optimization works at the application-wide level and considers control and data flows as well as the sacred knowledge about specific frameworks such as LINQ, MEF and others.

Let’s take a look at example.


Example 1. The slow code

    [Flags]
   
enum RunOptions
    {
        None = 0x00,
        PrepareDatabase = 0x01,
        SkipPlugins = 0x02
    }
 
   
class Engine
    {
       
public void Run(RunOptions options)
        {
           
if (options.HasFlag(RunOptions.PrepareDatabase))
                InitializeDatabase();
           
// ...
        }
 
       
// ...
    }

The code above uses Enum.HasFlag method to check whether PrepareDatabase flag is set. Being sweet in syntax, the code has astonishingly bad performance due to boxing operations that are invisilbly generated by C# compiler.


Example 2. The fast code. Produced by Eazfuscator.NET after optimizing the slow code

    public void Run(RunOptions options)
    {
       
if ((options & RunOptions.PrepareDatabase) == RunOptions.PrepareDatabase)
            InitializeDatabase();
       
// ...
    }

As you can see, Eazfuscator.NET emitted a functionally equivalent code. The result of optimization is 500x speed improvement of condition evaluation over original slow code.



That's not all. Eazfuscator.NET since version 3.3 carefully performs a bunch of other performance optimizations delivering the great speed experience to your customers. Speed is the part of wow effect and this is why we appreciate it so much at Eazfuscator.NET.

Right now there are about 20 manually crafted hotspot optimizers in Eazfuscator.NET. And the list will grow.



The optimization is on by default and works behind the scenes during obfuscation.

Some other improvements and fixes are included in the release as well.
You can download the new version right now or whenever you find it suitable.

Thank you!

Labels: ,