Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,6 @@
## 2026-06-15 - Optimize Multiple ToDictionary Allocations inside Workspace UI
**Learning:** In C#, executing multiple LINQ `.ToDictionary()` allocations on the same source collection (like building 9 different actor metrics dictionaries from `SimulationActors`) inside UI metric generation code allocates massive amounts of redundant enumerators, delegates, and intermediate dictionary structures on the UI thread, causing unnecessary memory allocation and garbage collection pauses.
**Action:** Replace multiple `.ToDictionary()` allocations on identical source collections with a single manual `foreach` loop that populates pre-allocated dictionaries simultaneously. This transforms an O(K*N) allocation into a tight O(N) loop and completely avoids LINQ overhead.
## 2024-05-31 - [Optimize ToDictionary with manual Dictionary copy constructor]
**Learning:** In C#, replacing `context.Supply.ToDictionary(pair => pair.Key, pair => pair.Value, Comparer)` with the native dictionary copy constructor `new Dictionary<string, double>(context.Supply, Comparer)` avoids multiple LINQ enumerator allocations and delegate creations for the hot `ToRoutingContext` path inside `TemporalNetworkSimulationEngine`.
**Action:** Replace direct `.ToDictionary` invocations with `new Dictionary(source, Comparer)` when copying dictionaries where the source implements `IDictionary<TKey, TValue>`.
Original file line number Diff line number Diff line change
Expand Up @@ -1072,9 +1072,9 @@ private static RoutingTrafficContext ToRoutingContext(TemporalTrafficContext con
Seed = context.Seed,
NodesById = context.NodesById,
ProfilesByNodeId = context.ProfilesByNodeId,
Supply = context.Supply.ToDictionary(pair => pair.Key, pair => pair.Value, Comparer),
SupplyUnitCosts = context.SupplyUnitCosts.ToDictionary(pair => pair.Key, pair => pair.Value, Comparer),
Demand = context.Demand.ToDictionary(pair => pair.Key, pair => pair.Value, Comparer),
Supply = new Dictionary<string, double>(context.Supply, Comparer),
SupplyUnitCosts = new Dictionary<string, double>(context.SupplyUnitCosts, Comparer),
Demand = new Dictionary<string, double>(context.Demand, Comparer),
MeetingDemandEligibleNodeIds = context.MeetingDemandEligibleNodeIds
};
}
Expand Down