I am trying to Create multiple assemblies at runtime. I am using Roslyn to compile each assembly in serial.
I am not able to leverage multithreading because Roslyn internally uses multithreading for compiling a single dll. The compilation time of a single dll with Roslyn is less than that of CodeDom but since with CodeDom I can parallel compile multiple dlls, the actual time for CodeDom is much less.
I tried to set the concurrent build option for Roslyn compilation to false and then used multithreading in my code, but this is also not efficient because the compile time for a single dll is more now. I am wondering if there is a work around for this issue
Update for timing analysis:
I have an 8 core processor. I have different sets of files on disk to be used for compiling 72 dlls.
In the first case, I am creating syntax trees from the files, creating references, creating options and compiling the dll using Emit for each dll in a serial fashion using a simple foreach
loop. It takes a total time of 488589 ms
In the second case, I am using a parallel.ForEach
with MaxDegreeOfParallelism = 7
and creating syntax trees, creating references, creating options and compiling the dll using Emit in the loop. It takes a total time of 514481 ms
In the both the case the concurrent build option is default: True.
As you can see there are no gains observed while using multithreading.