csnemes / tracer

Tracing rewriter using Fody
Apache License 2.0
93 stars 26 forks source link

Improved performance, when tracer is disabled: #111

Closed Audrius-Femtika closed 3 years ago

Audrius-Femtika commented 3 years ago
if (!$log.LogIsTraceEnabled)
{
    origin.. code...
}
csnemes commented 3 years ago

It seems for me that you duplicate the original code in each method. There is a copy with and another without the traces. So my problem is that it increases the size of the assembly. It would be better to run this check before calling trace enter and trace leave.

Audrius-Femtika commented 3 years ago

Hi, understand your concerns of bigger assembly size. I was previously doing it with 3 ifs. But copying instructions will result in fastest performance when no actual logging is done. The biggest impact improvement would result from 7 to 17, well realistically I do believe it will be 4 times less: https://docs.google.com/spreadsheets/d/1EypAMjZr9foFoNy6rjAyA8xaZQBmkImpzPbTANuPBiU/edit?usp=sharing

In your case there would be three if, extra boolean variable, still would need stopwatch function calling (well the last one is fixible. It possible to put under one of if's with extra work).

If you are still worry about size you could make it optional via parameter: PerfomanceOptimized=true. I do believe you would add this parameter 10x faster than me.

Also, I do believe this is best sample for coping Instructions. You can't find it on internet. All the instruction mappings with Exceptions copying. It will be good sample for "googlers".

Audrius-Femtika commented 3 years ago

It has bugs all are fixed. If you want bug free you merge from my fork. branch femtika-release