fix(scripts): memoize missing-assembly resolution in the UI script editor/sandbox
This commit is contained in:
@@ -41,6 +41,21 @@ namespace ZB.MOM.WW.ScadaBridge.CentralUI.ScriptAnalysis;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ScriptAnalysisService
|
public class ScriptAnalysisService
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Base Roslyn scripting options for every editor analysis, shared by
|
||||||
|
/// <see cref="SandboxOptions"/> and by the per-request options derived from it
|
||||||
|
/// (<c>ScriptOptions</c> is immutable-with-copy, so derivations inherit this).
|
||||||
|
///
|
||||||
|
/// <para>
|
||||||
|
/// Editor diagnostics compile on EVERY analysis request — one per debounced
|
||||||
|
/// keystroke burst — and Roslyn's default resolver re-resolves the transitive
|
||||||
|
/// closure of these references through <c>MetadataReference.CreateFromFile</c> on
|
||||||
|
/// every one of them, minting fresh <c>AssemblyMetadata</c> → <c>PEReader</c> →
|
||||||
|
/// <c>NativeHeapMemoryBlock</c> copies that nothing disposes. The shared
|
||||||
|
/// <see cref="SharedTrust.CachingScriptMetadataResolver"/> memoizes those
|
||||||
|
/// resolutions process-wide; see its doc for the full mechanism.
|
||||||
|
/// </para>
|
||||||
|
/// </summary>
|
||||||
private static readonly ScriptOptions DefaultOptions = ScriptOptions.Default
|
private static readonly ScriptOptions DefaultOptions = ScriptOptions.Default
|
||||||
.AddReferences(
|
.AddReferences(
|
||||||
typeof(object).Assembly,
|
typeof(object).Assembly,
|
||||||
@@ -50,6 +65,7 @@ public class ScriptAnalysisService
|
|||||||
typeof(Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo).Assembly,
|
typeof(Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo).Assembly,
|
||||||
typeof(Commons.Types.ScriptParameters).Assembly,
|
typeof(Commons.Types.ScriptParameters).Assembly,
|
||||||
typeof(SandboxScriptHost).Assembly)
|
typeof(SandboxScriptHost).Assembly)
|
||||||
|
.WithMetadataResolver(SharedTrust.CachingScriptMetadataResolver.Instance)
|
||||||
.AddImports(
|
.AddImports(
|
||||||
"System",
|
"System",
|
||||||
"System.Collections.Generic",
|
"System.Collections.Generic",
|
||||||
|
|||||||
Reference in New Issue
Block a user