Search code examples
c#roslynroslyn-code-analysisroslyn-project-system

Difference in performance when using Compiler API versus Workspace API in Roslyn


I know that there are several API provided by Roslyn; however, I was not sure what is the difference in performance when using Compiler API and Workspace API. Does Workspace API build the entire solution and generate the IL code?


Solution

  • The workspace API can be thought of as a helper just to make the Compiler API objects. So rather than having to manually call all the various compiler APIs to parse syntax trees and make Compilations, it does it for you. The interesting bits it really does is:

    1. Allow you to have multiple projects, where we're going to create multiple Compilations for each project and stitch them together. Again, nothing you can't do yourself, but it gets a bit verbose to do.
    2. When you have a higher level change to a project (change parse options, change references), we'll try to update the Compilations as efficiently as we can.
    3. Coordinates multiple threads asking for data, trying to share everything. i.e it's one big Lazy API that coordinates everything but also respects cancellation and such.