@@ -12,7 +12,7 @@ namespace NActors {
1212 TStackVec<THolder<IEventBase>, MaxEvents> Events;
1313 TStackVec<THolder<TEventSerializedData>, MaxEvents> Buffers;
1414 std::shared_ptr<std::atomic<TAtomicBase>> Counter;
15- ui64 NumBytes = 0 ;
15+ ui64 NumBytes = sizeof (TEvFreeItems) ;
1616
1717 ~TEvFreeItems () {
1818 if (Counter) {
@@ -76,6 +76,7 @@ namespace NActors {
7676 auto p = GetPendingEvent ();
7777 p->NumBytes += event->EventSerializedSize ;
7878 auto & events = p->Events ;
79+ p->NumBytes += sizeof (*ev);
7980 events.push_back (std::move (ev));
8081 trim = trim || events.size () >= TEvFreeItems::MaxEvents || p->NumBytes >= MaxBytesPerMessage;
8182 }
@@ -85,19 +86,24 @@ namespace NActors {
8586 auto p = GetPendingEvent ();
8687 p->NumBytes += event->EventSerializedSize ;
8788 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));
8992 trim = trim || buffers.size () >= TEvFreeItems::MaxEvents || p->NumBytes >= MaxBytesPerMessage;
9093 }
9194
9295 // free event and trim the cache if its size is exceeded
9396 event->Clear ();
9497 Cache.splice (Cache.end (), queue, event);
9598 if (Cache.size () >= FreeQueueTrimThreshold) {
96- auto & freeQueue = GetPendingEvent ()->FreeQueue ;
99+ auto p = GetPendingEvent ();
100+ auto & freeQueue = p->FreeQueue ;
97101 auto it = Cache.begin ();
98- std::advance (it, Cache.size () - MaxFreeQueueItems);
102+ size_t addSize = Cache.size () - MaxFreeQueueItems;
103+ std::advance (it, addSize);
99104 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;
101107 }
102108
103109 // release items if we have hit the limit
0 commit comments