martinothamar / Mediator

A high performance implementation of Mediator pattern in .NET using source generators.
MIT License
2.16k stars 71 forks source link

feat: refactor `IsLibReferencedByModule` using depth search or 60% speed up and 75% less memory usage #110

Closed TimothyMakkison closed 1 year ago

TimothyMakkison commented 1 year ago

refactor IsMediatorLibReferencedByTheModule using depth search

Keeps the exisitng algorithm using foreach loops (linq used 10MB of Func<IModuleSymbol, bool> and closures), uses an assembly cache and tracks if a module has been visited at a lower depth. This will be slower for larger projects as this is depth first, making it harder for visited to track if the module will be checked from a lower depth.

Closed if favour of #111.

Benchmarks

Original

Method Mean Error StdDev Gen 0 Gen 1 Allocated
Compile 81.18 ms 5.526 ms 16.29 ms 14500.0000 250.0000 23 MB

Changes

Method Mean Error StdDev Gen 0 Gen 1 Allocated
Compile 29.87 ms 1.744 ms 5.142 ms 2909.0909 181.8182 6 MB