Does Member Renamer have any impact to performance

160 views Asked by At

Does using Member Renamer have any performance impact because it will be doing it via Reflection: https://github.com/lunet-io/scriban/blob/master/doc/runtime.md#member-renamer

1

There are 1 answers

0
M.Hassan On BEST ANSWER

Scriban with or without Renamer is using reflection to get the public properties and methods.

Renamer is small step in its processing.

Have a look to the Renamer in the source code.

I did a benchmark using the smart BenchmarkDotNet

for the following template

    <ul id='products'>
      {% for product in products %}
        <li>
         product.name: <h2>{{ product.name }}</h2>
          product.price:   Only {{ product.price }}
           product.description:    {{ product.description | truncate: 15 }}
        </li>
      {% endfor %}
    </ul>

The size of data: List<Product> Products is 500

The result of benchmark:

                        Method |     Mean |     Error |    StdDev | Ratio |
    -------------------------- |---------:|----------:|----------:|------:|
        'Scriban with Renamer' | 3.125 ms | 0.0617 ms | 0.0711 ms |  1.00 |
                               |          |           |           |       |
     'Scriban without Renamer' | 3.070 ms | 0.0388 ms | 0.0363 ms |  1.00 |

    // * Hints *
    Outliers
      TemplateManager.'Scriban with Renamer': Clr -> 1 outlier  was  removed

    // * Legends *
      Mean   : Arithmetic mean of all measurements
      Error  : Half of 99.9% confidence interval
      StdDev : Standard deviation of all measurements
      Ratio  : Mean of the ratio distribution ([Current]/[Baseline])
      1 ms   : 1 Millisecond (0.001 sec)

As you see the difference (in case of Renamer) is about: 0.055 ms
There is approximately no difference

Conclusion: No effect in case of Renamer

Note: The numbers in this benchmark may be different in other machines based on CPU/memory/...etc, but the conclusion is the same.