perf(runtime): O(1) attribute resolution, precomputed types, coalesced static writes, shared JSON options
This commit is contained in:
@@ -177,6 +177,15 @@ public class ScriptAnalysisService
|
||||
private const int SandboxMaxConsoleChars = 32_000;
|
||||
private const int SandboxMaxReturnJsonChars = 32_000;
|
||||
|
||||
/// <summary>
|
||||
/// Shared options for the per-Test-Run return-value JSON serialize in
|
||||
/// <see cref="SerializeReturn"/> (perf remediation, arch-review WP1.5) — avoids
|
||||
/// allocating a new <see cref="JsonSerializerOptions"/> per run. Settings preserved
|
||||
/// exactly.
|
||||
/// </summary>
|
||||
private static readonly JsonSerializerOptions SandboxReturnJsonOptions =
|
||||
new() { WriteIndented = true };
|
||||
|
||||
private const int SandboxMaxCallSharedDepth = 16;
|
||||
|
||||
/// <summary>
|
||||
@@ -520,7 +529,7 @@ public class ScriptAnalysisService
|
||||
var typeName = value.GetType().Name;
|
||||
try
|
||||
{
|
||||
var json = JsonSerializer.Serialize(value, new JsonSerializerOptions { WriteIndented = true });
|
||||
var json = JsonSerializer.Serialize(value, SandboxReturnJsonOptions);
|
||||
if (json.Length > SandboxMaxReturnJsonChars)
|
||||
json = json[..SandboxMaxReturnJsonChars] + "\n… (truncated)";
|
||||
return (json, typeName);
|
||||
|
||||
Reference in New Issue
Block a user