Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Firmament: share immutable syntax trees across identical parses
Claude5e4c90b38c5b
diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/Syntax/FirmamentSyntaxParser.cs b/Aetheris.Kernel.Firmament/FirmamentV2/Syntax/FirmamentSyntaxParser.csindex 4a494623..d8ca8c9f 100644--- a/Aetheris.Kernel.Firmament/FirmamentV2/Syntax/FirmamentSyntaxParser.cs+++ b/Aetheris.Kernel.Firmament/FirmamentV2/Syntax/FirmamentSyntaxParser.cs@@ -8,9 +8,25 @@ public static class FirmamentSyntaxParserpublic static SyntaxParseResult Parse(string source, string sourceFile = "inline"){ArgumentNullException.ThrowIfNull(source);- return new Parser(source, sourceFile).Parse();+ ArgumentNullException.ThrowIfNull(sourceFile);+ var key = (sourceFile, source);+ lock (ParseCache)+ if (ParseCache.TryGetValue(key, out var cached)) return cached;+ var result = new Parser(source, sourceFile).Parse();+ lock (ParseCache)+ {+ // The trees are immutable, so identical text can share one parse. Compilation+ // helpers re-parse the same document many times (13,600 parses in one guitar+ // build); clearing on overflow keeps memory bounded without LRU bookkeeping.+ if (ParseCache.Count >= ParseCacheCapacity) ParseCache.Clear();+ ParseCache[key] = result;+ }+ return result;}+ private const int ParseCacheCapacity = 256;+ private static readonly Dictionary<(string File, string Source), SyntaxParseResult> ParseCache = new();+private sealed class ParseFailure : Exception;private sealed class Parser{diff --git a/Aetheris.Web.Perf/Aetheris.Web.Perf.csproj b/Aetheris.Web.Perf/Aetheris.Web.Perf.csprojindex a6f04cc0..1fe5dbcf 100644--- a/Aetheris.Web.Perf/Aetheris.Web.Perf.csproj+++ b/Aetheris.Web.Perf/Aetheris.Web.Perf.csproj@@ -12,6 +12,7 @@<ProjectReference Include="..\Aetheris.Kernel.Firmament\Aetheris.Kernel.Firmament.csproj" /><Compile Include="..\Aetheris.Web.Runtime\Program.cs" Link="WebProgram.cs" /><Compile Include="..\Aetheris.Web.Runtime\WebResponseBridge.cs" Link="WebResponseBridge.cs" />+ <Compile Include="..\Aetheris.Web.Runtime\Program.Measurement.cs" Link="WebProgram.Measurement.cs" /><Compile Include="PerfProgram.cs" /><Compile Include="ShowcasePerf.cs" /><Compile Include="CompareStep.cs" />