@@ -37,6 +37,8 @@ class AllocationBuffer3 : public AllocationBufferBase<ElementType> {
3737 WriterData& writerData = m_writersData[writerIndex].get ();
3838 while (true ) {
3939 writerData.queueIndex = (writerData.queueIndex + 1 ) % m_queues.size ();
40+ const uint64_t nextQueueIndex = (writerData.queueIndex + 1 ) % m_queues.size ();
41+ m_queues[nextQueueIndex]->prefetch ();
4042 ElementType* res = m_queues[writerData.queueIndex ]->tryPop ();
4143 if (res) {
4244 return res;
@@ -49,6 +51,8 @@ class AllocationBuffer3 : public AllocationBufferBase<ElementType> {
4951 WriterData& writerData = m_writersData[writerIndex].get ();
5052 while (true ) {
5153 writerData.queueIndex = (writerData.queueIndex + 1 ) % m_queues.size ();
54+ const uint64_t nextQueueIndex = (writerData.queueIndex + 1 ) % m_queues.size ();
55+ m_queues[nextQueueIndex]->prefetch ();
5256 if (m_queues[writerData.queueIndex ]->tryPush (element)) {
5357 return ;
5458 }
@@ -83,6 +87,16 @@ class AllocationBuffer3 : public AllocationBufferBase<ElementType> {
8387 return true ;
8488 }
8589
90+ void prefetch () noexcept
91+ {
92+ __builtin_prefetch (
93+ pointers.data () + pointers.size () - 1 ,
94+ PrefetchMode::Read,
95+ Locality::High);
96+ __builtin_prefetch (&pointers, PrefetchMode::Write, Locality::High);
97+ __builtin_prefetch (&lock, PrefetchMode::Write, Locality::High);
98+ }
99+
86100 private:
87101 std::vector<ElementType*> pointers;
88102 std::atomic_flag lock {false };
@@ -92,7 +106,7 @@ class AllocationBuffer3 : public AllocationBufferBase<ElementType> {
92106 };
93107
94108 struct WriterData {
95- uint16_t queueIndex;
109+ uint64_t queueIndex;
96110 };
97111
98112 std::vector<ElementType> m_objectPool;
0 commit comments