@@ -12,7 +12,7 @@ namespace NActors {
12
12
TStackVec<THolder<IEventBase>, MaxEvents> Events;
13
13
TStackVec<THolder<TEventSerializedData>, MaxEvents> Buffers;
14
14
std::shared_ptr<std::atomic<TAtomicBase>> Counter;
15
- ui64 NumBytes = 0 ;
15
+ ui64 NumBytes = sizeof (TEvFreeItems) ;
16
16
17
17
~TEvFreeItems () {
18
18
if (Counter) {
@@ -76,6 +76,7 @@ namespace NActors {
76
76
auto p = GetPendingEvent ();
77
77
p->NumBytes += event->EventSerializedSize ;
78
78
auto & events = p->Events ;
79
+ p->NumBytes += sizeof (*ev);
79
80
events.push_back (std::move (ev));
80
81
trim = trim || events.size () >= TEvFreeItems::MaxEvents || p->NumBytes >= MaxBytesPerMessage;
81
82
}
@@ -85,19 +86,24 @@ namespace NActors {
85
86
auto p = GetPendingEvent ();
86
87
p->NumBytes += event->EventSerializedSize ;
87
88
auto & buffers = p->Buffers ;
88
- buffers.emplace_back (event->Buffer .Release ());
89
+ auto && bufferReleased = event->Buffer .Release ();
90
+ p->NumBytes += sizeof (*bufferReleased);
91
+ buffers.emplace_back (std::move (bufferReleased));
89
92
trim = trim || buffers.size () >= TEvFreeItems::MaxEvents || p->NumBytes >= MaxBytesPerMessage;
90
93
}
91
94
92
95
// free event and trim the cache if its size is exceeded
93
96
event->Clear ();
94
97
Cache.splice (Cache.end (), queue, event);
95
98
if (Cache.size () >= FreeQueueTrimThreshold) {
96
- auto & freeQueue = GetPendingEvent ()->FreeQueue ;
99
+ auto p = GetPendingEvent ();
100
+ auto & freeQueue = p->FreeQueue ;
97
101
auto it = Cache.begin ();
98
- std::advance (it, Cache.size () - MaxFreeQueueItems);
102
+ size_t addSize = Cache.size () - MaxFreeQueueItems;
103
+ std::advance (it, addSize);
99
104
freeQueue.splice (freeQueue.end (), Cache, Cache.begin (), it);
100
- trim = true ;
105
+ p->NumBytes += (sizeof (TEventHolder) + 5 * sizeof (void *)) * addSize;
106
+ trim = trim || p->NumBytes >= MaxBytesPerMessage;
101
107
}
102
108
103
109
// release items if we have hit the limit
0 commit comments