Compilify is an online compiler as a service, started by Justin Rusbatch, which works on top of the Roslyn CTP. Started recently, it has already received a good amount of attention from the .NET community. We got in touch with Justin to ask him some questions.
InfoQ: Could you introduce yourself to our readers?
Justin: My name is Justin. I’m a self-taught developer working for a small .NET-based web development company in central Pennsylvania. I taught myself C# while working night-shifts as a Computer Operator, in between mounting tapes for a mainframe. I worked with ASP.NET webforms for a year, but I moved on to the MVC framework when it came out and I’ve been developing sites with that ever since. I enjoy learning other languages. I have some experience with Ruby on Rails, node.js, and F#.
InfoQ: You recently started Compilify - could you explain what is the purpose of this project?
Justin: Compilify (pronounced “compile-ify”) was inspired by many things. One of the primary sources of inspiration was the C# Interactive window that the Roslyn CTP brings to Visual Studio. This window provides a REPL environment that can be used to execute individual statements against the projects they’re developing and receive immediate results.
Compilify makes the .NET compiler completely portable and accessible through a fast, simple interface that fosters sharing and collaboration. It’s not an IDE in your browser, nor will it ever be. It’s simpler than that. You shouldn’t need to launch an IDE or create a new console project to experiment with a new idea that only takes a few lines of code. A developer’s time is incredibly valuable. Spending too much time thinking about a problem without actually trying solutions results in over-engineered solutions, killing productivity.
It also has a lot of potential as an educational tool for people who don’t know C# but want to try it. Downloading, installing, and launching Visual Studio can intimidate new developers. In fact, some developers might not install Visual Studio because of all the other applications that it install with it -- leading to an even more overwhelming experience. Compilify lets users get their hands dirty without needing to install anything -- not even a browser plugin.
InfoQ: Could you explain how Compilify works under the covers?
Justin: Lots of magic and coffee!
When the user submits code to the server for execution, a persistent connection is opened with SignalR. The web server wraps the code in an object with the SignalR connection ID that it was received from and then added to a processing queue on my Redis server. This frees up the web server to continue handling requests from other users.
Background workers do the heavy lifting. In order to prevent any malicious code from running, a new low-trust AppDomain is created to act as a secure sandbox for each execution. I haven’t taken the time to profile the performance, but so far I haven’t had a reason to worry about performance in this part of the application. Only essential assemblies are loaded into the AppDomain in addition to the user’s code.
The user’s code is wrapped in a method, parsed into a compilation unit, and emitted into an assembly. The assembly is loaded inside the sandbox and the method that the user’s code was wrapped in is called. the result is serialized and returned to the worker. I perform this work in a separate thread that I can cancel if too much time is taken (the time limit is currently set at 5 seconds).
Once the result has been returned to the worker, it’s published back to Redis through a pub/sub channel along with the SignalR connection ID that originally made the request for the code to be executed. The web server subscribes to this channel on App_Start. SignalR is then used to forward any messages received in through this channel to the appropriate client.
This complex architecture was necessary to facilitate the secure execution of the user’s code, and to ensure the stability of the web servers.
Read more: InfoQ
Read more: Compilify
QR: