-
Notifications
You must be signed in to change notification settings - Fork 244
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
CodeCom Evaluator gets slower after many LoadCode iterations #6
Comments
…s (added Roslyn and Mono support)
* Issue #6: CodeCom Evaluator gets slower after many LoadCode iterations
* Issue #6: CodeCom Evaluator gets slower after many LoadCode iterations (removed test code)
It is indeed by design. Well kind of :) The app domain assemblies are referenced by default and it is intended behavior. However inability to change this behavior is rather a mistake. The following is a work around the problem. var script = CSScript.CodeDomEvaluator
.Reset(false)
.LoadCode(...) It should work but ideally there should be a config value for that. I just published on NuGet a hot fix release (v3.13.2.0) that has a new EvaluatorConfig member to address the problem directly: CSScript.EvaluatorConfig.RefernceDomainAsemblies = false; |
Thanks, works like a charm. One thing I noticed though: when I set this flag to false, I am no longer able to debug the dynamically loaded assembly. Before, I could just open the generated C# file from the "dynamic" folder, and put a break point in it. Any idea why this happens? |
There are a usual suspects for debugging difficulties:
|
Thanks, I was able to work around it. Off-topic, a question about loading in the current AppDomain: I am aware of the AppDomain load/unload issues and the work-around with remoting.
Koen |
Hi Koen, It's actually great that you are aware about the implications of dynamic assembly loading. I tried to make it very clear in the CS-Script documentation that the implications do exist and any work around does come with the cost. To my surprise two major C# scripting alternatives (Mono and Roslyn) resorted to the blunt ignoring of the problem. Anyway, my view on the matter was always straightforward: use local loading if you can afford it and remoting if you have to. If you don't have permanently growing footprint of loaded scripts/assemblies then probably local loading is the most practical option. The only downside apart from the memory consumption can be potential assembly probing challenges with such a wast amount of the loaded assemblies but these challenges can only become real if your scripts reference each other. If it's not your case then provably you are OK. As for Mono compiler 'eval-0' output it's completely out of CS-Script control. These messages are from the Mono engine and I don't (well no longer) believe "Unloaded 'eval-0'" means that some dynamically loaded assembly was unloaded. You see, by endless experiments with Mono I found the way of compiling/loading the constantly changing script without increasing the memory footprint. It looks like Mono guys did some magic under the hood. This is what became CS-Script integration with Mono (Mono Evaluator). The various scenarios and their effect on memory are presented in the "/samples/Hosting/Legacy Samples/CompilerAsService/MemoryManagement.cs" sample. But... unfortunately I received user reports indicating that Mono "magic" not always work and the AppDomain the assemblies can get stuck in memory even with Mono. Cheers, |
Closed as Fixed |
If the CodeCom Evaluator is used to compile N different scripts OR the CodeCom Evaluator is used with Caching disabled,
LoadCode becomes slower each iteration.
This can be seen from this xUnit test, created in a clone of the cs-script repo.
The preconditions for this behavior to occur are:
The events leading up to this behavior are:
(happens in the Reset(true) call in the CodeComEvaluator ctor)
all of these assemblies will be referenced on iteration N.
will have all of these assemblies in compilerParams.ReferencedAssemblies, leading to slower
compilation
This makes it hard to use CSScript.Evaluator.LoadCode in a server environment.
Is it "by design" that all previously dynamically compiled assemblies are referenced?
Are there any work-arounds for this behavior?
(other than using LoadCodeRemotely instead of LoadCode)
(other than using EvaluatorAccess.Singleton instead of EvaluatorAccess.AlwaysCreate)
Thanks for your time,
Koen
The text was updated successfully, but these errors were encountered: