From 97e250129ecdf7bc5d62ea6fdb7001fb5d932aa5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A1nos=20Benjamin=20Antal?=
 <antaljanosbenjamin@users.noreply.github.com>
Date: Mon, 24 Apr 2023 16:22:22 +0200
Subject: [PATCH]  Change `AccumulateCursor` to use  `utils::pmr::deque` (#888)

* Increase performance by eliminating unnecessary `TypedValue` copies
---
 src/query/plan/operator.cpp |  3 ++-
 src/utils/pmr/deque.hpp     | 23 +++++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 src/utils/pmr/deque.hpp

diff --git a/src/query/plan/operator.cpp b/src/query/plan/operator.cpp
index 2203f36aa..fb729e392 100644
--- a/src/query/plan/operator.cpp
+++ b/src/query/plan/operator.cpp
@@ -53,6 +53,7 @@
 #include "utils/likely.hpp"
 #include "utils/logging.hpp"
 #include "utils/memory.hpp"
+#include "utils/pmr/deque.hpp"
 #include "utils/pmr/list.hpp"
 #include "utils/pmr/unordered_map.hpp"
 #include "utils/pmr/unordered_set.hpp"
@@ -3248,7 +3249,7 @@ class AccumulateCursor : public Cursor {
  private:
   const Accumulate &self_;
   const UniqueCursorPtr input_cursor_;
-  utils::pmr::vector<utils::pmr::vector<TypedValue>> cache_;
+  utils::pmr::deque<utils::pmr::vector<TypedValue>> cache_;
   decltype(cache_.begin()) cache_it_ = cache_.begin();
   bool pulled_all_input_{false};
 };
diff --git a/src/utils/pmr/deque.hpp b/src/utils/pmr/deque.hpp
new file mode 100644
index 000000000..ecfbf5fc0
--- /dev/null
+++ b/src/utils/pmr/deque.hpp
@@ -0,0 +1,23 @@
+// Copyright 2023 Memgraph Ltd.
+//
+// Use of this software is governed by the Business Source License
+// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
+// License, and you may not use this file except in compliance with the Business Source License.
+//
+// As of the Change Date specified in that file, in accordance with
+// the Business Source License, use of this software will be governed
+// by the Apache License, Version 2.0, included in the file
+// licenses/APL.txt.
+
+#pragma once
+
+#include <deque>
+
+#include "utils/memory.hpp"
+
+namespace memgraph::utils::pmr {
+
+template <class T>
+using deque = std::deque<T, utils::Allocator<T>>;
+
+}  // namespace memgraph::utils::pmr