From b9ae685c488032023318936b681a34520dcab11e Mon Sep 17 00:00:00 2001 From: antoniofilipovic Date: Thu, 2 Feb 2023 13:38:41 +0100 Subject: [PATCH] introduce std::unordered_map in Parameters to reduce lookup --- src/query/interpret/eval.hpp | 16 ++++++++-------- src/query/parameters.hpp | 15 +++++++-------- src/query/plan/operator.cpp | 16 ++++++++-------- src/storage/v2/vertex_accessor.cpp | 16 ++++++++-------- 4 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/query/interpret/eval.hpp b/src/query/interpret/eval.hpp index 8ed737eea..a0e4bab42 100644 --- a/src/query/interpret/eval.hpp +++ b/src/query/interpret/eval.hpp @@ -231,7 +231,7 @@ class ExpressionEvaluator : public ExpressionVisitor { } TypedValue Visit(SubscriptOperator &list_indexing) override { - auto start = std::chrono::steady_clock::now(); + // auto start = std::chrono::steady_clock::now(); ReferenceExpressionEvaluator referenceExpressionEvaluator(frame_, symbol_table_, ctx_, dba_, view_); @@ -255,14 +255,14 @@ class ExpressionEvaluator : public ExpressionVisitor { if (index_int >= static_cast(list.size()) || index_int < 0) return TypedValue(ctx_->memory); // NOTE: Explicit move is needed, so that we return the move constructed // value and preserve the correct MemoryResource. - auto end = std::chrono::steady_clock::now(); - std::chrono::duration dif = end - start; - total2 += dif; + // auto end = std::chrono::steady_clock::now(); + // std::chrono::duration dif = end - start; + // total2 += dif; - if (total2 > new_print2) { - std::cout << "Time difference visit = " << total2.count() << "[s]" << std::endl; - new_print2 += static_cast>(1.0); - } + // if (total2 > new_print2) { + // std::cout << "Time difference visit = " << total2.count() << "[s]" << std::endl; + // new_print2 += static_cast>(1.0); + // } return TypedValue(list[index_int]); } diff --git a/src/query/parameters.hpp b/src/query/parameters.hpp index 08da3f3e7..eb6de8859 100644 --- a/src/query/parameters.hpp +++ b/src/query/parameters.hpp @@ -1,4 +1,4 @@ -// Copyright 2022 Memgraph Ltd. +// 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 @@ -32,7 +32,7 @@ struct Parameters { * @param position Token position in query of value. * @param value */ - void Add(int position, const storage::PropertyValue &value) { storage_.emplace_back(position, value); } + void Add(int position, const storage::PropertyValue &value) { storage_.emplace(position, value); } /** * Returns the value found for the given token position. @@ -41,9 +41,8 @@ struct Parameters { * @return Value for the given token position. */ const storage::PropertyValue &AtTokenPosition(int position) const { - auto found = std::find_if(storage_.begin(), storage_.end(), [&](const auto &a) { return a.first == position; }); - MG_ASSERT(found != storage_.end(), "Token position must be present in container"); - return found->second; + MG_ASSERT(storage_.contains(position), "Token position must be present in container"); + return storage_.at(position); } /** @@ -53,9 +52,9 @@ struct Parameters { * @param position Which stripped param is sought. * @return Token position and value for sought param. */ - const std::pair &At(int position) const { + const storage::PropertyValue &At(int position) const { MG_ASSERT(position < static_cast(storage_.size()), "Invalid position"); - return storage_[position]; + return storage_.at(position); } /** Returns the number of arguments in this container */ @@ -65,7 +64,7 @@ struct Parameters { auto end() const { return storage_.end(); } private: - std::vector> storage_; + std::unordered_map storage_; }; } // namespace memgraph::query diff --git a/src/query/plan/operator.cpp b/src/query/plan/operator.cpp index 77b0f4f48..4465a6f99 100644 --- a/src/query/plan/operator.cpp +++ b/src/query/plan/operator.cpp @@ -212,7 +212,7 @@ VertexAccessor &CreateLocalVertex(const NodeCreationInfo &node_info, Frame *fram // TODO: PropsSetChecked allocates a PropertyValue, make it use context.memory // when we update PropertyValue with custom allocator. - auto start = std::chrono::steady_clock::now(); + // auto start = std::chrono::steady_clock::now(); if (const auto *node_info_properties = std::get_if(&node_info.properties)) { for (const auto &[key, value_expression] : *node_info_properties) { PropsSetChecked(&new_node, key, value_expression->Accept(evaluator)); @@ -224,14 +224,14 @@ VertexAccessor &CreateLocalVertex(const NodeCreationInfo &node_info, Frame *fram PropsSetChecked(&new_node, property_id, value); } } - auto end = std::chrono::steady_clock::now(); - std::chrono::duration dif = end - start; - total += dif; + // auto end = std::chrono::steady_clock::now(); + // std::chrono::duration dif = end - start; + // total += dif; - if (total > new_print) { - std::cout << "Time difference props set checked = " << total.count() << "[s]" << std::endl; - new_print += static_cast>(10.0); - } + // if (total > new_print) { + // std::cout << "Time difference props set checked = " << total.count() << "[s]" << std::endl; + // new_print += static_cast>(10.0); + // } (*frame)[node_info.symbol] = new_node; return (*frame)[node_info.symbol].ValueVertex(); diff --git a/src/storage/v2/vertex_accessor.cpp b/src/storage/v2/vertex_accessor.cpp index fdf6aba4e..535e4f2da 100644 --- a/src/storage/v2/vertex_accessor.cpp +++ b/src/storage/v2/vertex_accessor.cpp @@ -212,7 +212,7 @@ Result> VertexAccessor::Labels(View view) const { } Result VertexAccessor::SetProperty(PropertyId property, const PropertyValue &value) { - auto start = std::chrono::steady_clock::now(); + // auto start = std::chrono::steady_clock::now(); utils::MemoryTracker::OutOfMemoryExceptionEnabler oom_exception; std::lock_guard guard(vertex_->lock); @@ -233,14 +233,14 @@ Result VertexAccessor::SetProperty(PropertyId property, const Pro UpdateOnSetProperty(indices_, property, value, vertex_, *transaction_); - auto end = std::chrono::steady_clock::now(); - std::chrono::duration dif = end - start; - total += dif; + // auto end = std::chrono::steady_clock::now(); + // std::chrono::duration dif = end - start; + // total += dif; - if (total > new_print) { - std::cout << "Time difference = " << total.count() << "[s]" << std::endl; - new_print += static_cast>(2.0); - } + // if (total > new_print) { + // std::cout << "Time difference = " << total.count() << "[s]" << std::endl; + // new_print += static_cast>(2.0); + // } return std::move(current_value); }