Skip to content

Latest commit

 

History

History
77 lines (39 loc) · 2.14 KB

README.md

File metadata and controls

77 lines (39 loc) · 2.14 KB

DisruptorPlayground

Methodology

  • Measure early and frequently

  • Focus on critical paths

Framework specifics

  • Beware of Exception throwing performance cost

  • Avoid string manipulation, use StringBuilder or better alternative

  • Avoid Reflection

  • Careful with foreach loop (state machine allocation)

  • Careful with async (state machine allocation)

Beware of Lock contention

Object Reuse

  • Object caching

Object Pooling

Avoid Allocation

  • async - use ValueTask when high probability to return the task result directly

  • Avoid closures in lambda

  • Avoid yield (state machine allocation)

  • Avoid LINQ

  • Promote allocation on stack - stackalloc and/or Span<T> for temporary local data storage

  • Promote ValueTuple, being a struct

  • Promote struct

    • Allocating a reference type has a cost, but passing it around is cheap, allocation a value type is cheap, but passing it around has a cost (which can be handled using a struct ByRef)

    • Thread safe

    • JIT optimization

    • Avoid boxing of value types

      • Use generics with constraints Do<T> where T: ISomething - readonly struct TImplem: ISomething {}, which is JIT optimization friendly

      • use readonly, ref and in keyword for flexibility, both as function parameter and return value signature

        • ref : pass by reference, property modification allowed- use a readonly struct otherwise a defensive copy is created

        • in => pass by reference, no property modification allowed - use a readonly struct otherwise a defensive copy is created

      • use ref struct definition to garantee that the struct will never be heap allocated