1- using System . Buffers ;
21using HotChocolate . Execution ;
32using HotChocolate . Fusion . Execution . Nodes ;
43using HotChocolate . Fusion . Text . Json ;
@@ -8,6 +7,8 @@ namespace HotChocolate.Fusion.Execution.Results;
87
98internal sealed partial class FetchResultStore
109{
10+ private const int MaxDictionaryRetainCapacity = 256 ;
11+
1112 /// <summary>
1213 /// Initializes the <see cref="FetchResultStore"/> for a new request.
1314 /// </summary>
@@ -64,56 +65,30 @@ public void Reset()
6465 /// Cleans the store for return to the pool.
6566 /// Releases per-request state while retaining reusable buffers.
6667 /// </summary>
67- internal void Clean ( int maxCollectTargetRetainLength , int maxDictionaryRetainCapacity )
68+ internal void Clean ( )
6869 {
69- // drain and dispose per-request memory
7070 while ( _memory . TryPop ( out var memory ) )
7171 {
7272 memory . Dispose ( ) ;
7373 }
7474
75- // return path segments to global pool and reset local pool
7675 _pathPool . Dispose ( ) ;
7776 _pathPool = null ! ;
7877
79- // clear errors
8078 _errors ? . Clear ( ) ;
8179 _pocketedErrors ? . Clear ( ) ;
8280
83- // reset variable writer (returns excess chunks, keeps the first)
84- _variableWriter . Clean ( ) ;
85-
86- // clear collect target arrays to unroot CompositeResultDocument references;
87- // if they grew too large during a burst, swap them for smaller ones.
88- TrimOrClearBuffer ( ref _collectTargetA , maxCollectTargetRetainLength ) ;
89- TrimOrClearBuffer ( ref _collectTargetB , maxCollectTargetRetainLength ) ;
90- TrimOrClearBuffer ( ref _collectTargetCombined , maxCollectTargetRetainLength ) ;
81+ _builderPool . Clean ( ) ;
9182
92- // clear dictionaries/hashsets; drop oversized ones.
93- TrimOrClear ( ref _seenPaths , maxDictionaryRetainCapacity , ReferenceEqualityComparer . Instance ) ;
94- _variableDedupTable . Clear ( ) ;
83+ TrimOrClear ( ref _seenPaths , MaxDictionaryRetainCapacity , ReferenceEqualityComparer . Instance ) ;
9584
96- // null out per-request references
9785 _result = default ! ;
9886 _valueCompletion = default ! ;
9987 _schema = default ! ;
10088 _errorHandler = default ! ;
10189 _operation = default ! ;
10290 }
10391
104- private static void TrimOrClearBuffer ( ref CompositeResultElement [ ] buffer , int maxRetainLength )
105- {
106- if ( buffer . Length > maxRetainLength )
107- {
108- ArrayPool < CompositeResultElement > . Shared . Return ( buffer , clearArray : true ) ;
109- buffer = ArrayPool < CompositeResultElement > . Shared . Rent ( 64 ) ;
110- }
111- else
112- {
113- buffer . AsSpan ( ) . Clear ( ) ;
114- }
115- }
116-
11792 private static void TrimOrClear < TKey > (
11893 ref HashSet < TKey > set ,
11994 int maxRetainCapacity ,
0 commit comments