26

What is CaaS (Compiler As A Service) in regards to the Roslyn project?

How does using the Roslyn feature improve the performance of a C# application over the current C# 4.0 compiler?

What are the known limitations/issues in the Roslyn-CTP?

p.campbell
  • 98,673
  • 67
  • 256
  • 322
S2S2
  • 8,322
  • 5
  • 37
  • 65

4 Answers4

19

What exactly does Compiler as a Service (CaaS) mean in relation to Roslyn? You can watch a video where Anders Hejlsberg explains that (talk about Roslyn starts at 35 minutes in). Basically, the old C# compiler is a "black box": source code comes in, compiled assemblies come out. Roslyn gives you access inside that box. That means you can get syntactic and semantic information about some code, modify it and give it back to the compiler to process it further. You can use that to do code analysis, refactoring, code generation and more.

There is a long list of features that are not implemented in the current CTP on the Roslyn forum.

Regarding performance, I don't think that's among the goals of Roslyn. Besides, the JIT compiler is more important for performance optimizations than the C#/VB compiler. And Roslyn replaces the C#/VB compiler, not th JIT compiler.

svick
  • 236,525
  • 50
  • 385
  • 514
  • Just an update : As per microsoft performance is actually one of the key "features" they now want in Roslyn http://blogs.msdn.com/b/csharpfaq/archive/2014/01/15/roslyn-performance-matt-gertz.aspx – skewl84 May 28 '14 at 23:48
  • 3
    @skewl84 The performance of the Roslyn compiler itself, yes. But not the performance of the compiled code, which is what the question asked about. – svick May 28 '14 at 23:54
  • 3
    @svick.. Oops sorry I was carried away by the awesomeness of "Roslyn".. my bad – skewl84 May 29 '14 at 03:57
9

Compiler as a service (CaaS) with respect to Roslyn just means the compilation process is broken down into pieces with a public API that lets you examine the syntactic and semantic models built by the compiler during compilation. The Roslyn C# and VB compilers completely replace the existing compilers, so you can continue to use them in the same way you use the compilers today (as separate executables that converts text files into .net assemblies.) You can also use the compilers as a library of APIs that help you build tools that do deeper or different kinds of code analysis.

Roslyn does not give you specific performance advantage over using the existing compilers because when Roslyn releases they will be one and the same. However, it is possible to use roslyn to build specialized code refactorings that improve your source code.

James Wiseman
  • 29,946
  • 17
  • 95
  • 158
Matt Warren
  • 1,956
  • 14
  • 15
7

One advantage that Roslyn has is when your application needs a scripting interface. With Roslyn, you can directly compile the script as C# source code with same programming possibilities as the source of the application and directly use it.

S2S2
  • 8,322
  • 5
  • 37
  • 65
Nigel Findlater
  • 1,684
  • 14
  • 34
  • do you mean after compiling, the script is converted to C# source code? – S2S2 Jan 19 '12 at 07:06
  • Yes, the user could be given a text box into which he can script in a high level language like VB.NET or C# and the the code can be directly compiled and used by the application... – Nigel Findlater Jan 19 '12 at 08:59
  • You can do that without Roslyn. VS currently supports compiling a source code string into the current project at runtime. – IamIC Dec 18 '14 at 05:51
3

I'm excited about Roslyn because it will allow an easier way to implement Aspect Oriented Programming. Using AOP, you can write common "policies" and apply them across your code instead of spreading it across all your code. Using the Roslyn compiler you could weave these policies across your code at compile time, and keep cross-cutting concerns for polluting your business code. If you want some use cases, check out what PostSharp lists as their use cases

http://www.sharpcrafters.com/

  • Logging policies
  • Exception handling policies
  • Automatic thread synchronization (make sure the right things get called on the UI thread)
  • Automatic auditing of function calls
  • Automatically generate INotifyPropertyChanged implementations for automatic properties
  • and more
Matt Dotson
  • 5,887
  • 1
  • 23
  • 23