Persistent DSL Caching
This is a note to myself, because I don't have the time for a proper post. When you are dealing with a DSL that contains more than just a few scripts, you really being to care about compilation times. Even with caching, this can be a problem.
The solution is the same that we have been using for the last three to four decades, don't compile if the source hasn't changed.
The code to make this happen using Rhino DSL is here:
public override CompilerContext Compile(string[] urls) { var outputAssemblyName = OutputAssemblyName(urls); if (CanUseCachedVersion(outputAssemblyName, urls)) return new CompilerContext { GeneratedAssembly = Assembly.Load(File.ReadAllBytes(outputAssemblyName)) }; return base.Compile(urls); } private bool CanUseCachedVersion(string outputAssemblyName, string[] urls) { var asm = new FileInfo(outputAssemblyName); if(asm.Exists==false) return false; foreach (var url in urls) { if(File.GetLastWriteTime(url) > asm.LastWriteTime) return false; } return true; }
And in the CustomizeCompiler method:
protected override void CustomizeCompiler(BooCompiler compiler, CompilerPipeline pipeline, string[] urls) { compiler.Parameters.OutputAssembly = OutputAssemblyName(urls); // add implicit base class here... if (pipeline.Find(typeof(SaveAssembly)) == -1) pipeline.Add(new SaveAssembly());
}
It is impossible to overstate how big a difference this can make.
Comments
Would be nice if this was part of boo/Rhino DSL instead of needing to be implemented
Please submit a patch and tests for this.
Comment preview