From c95afbed19bd4386b8ae55b9bb5c7026ecfbe6ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20R=C3=A4tzel?= Date: Sat, 5 Oct 2024 21:55:50 +0000 Subject: [PATCH] Speed up building the dictionary of reused Elm value encodings --- implement/Pine.Core/ReusedInstances.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/implement/Pine.Core/ReusedInstances.cs b/implement/Pine.Core/ReusedInstances.cs index d729596c..607c5b37 100644 --- a/implement/Pine.Core/ReusedInstances.cs +++ b/implement/Pine.Core/ReusedInstances.cs @@ -343,9 +343,15 @@ [.. elmRecord.Fields.Select(kvp => (kvp.FieldName, reusedInstances[kvp.Value]))] { var encodedDict = new Dictionary(); - foreach (var item in ElmValues) + var elmValuesSorted = + ElmValues + .OrderBy(ev => ev.ContainedNodesCount) + .ToList(); + + foreach (var item in elmValuesSorted) { - encodedDict[item] = ElmInteractive.ElmValueEncoding.ElmValueAsPineValue(item); + encodedDict[item] = + ElmInteractive.ElmValueEncoding.ElmValueAsPineValue(item, encodedDict); } ElmValueEncoding =