introduce std::unordered_map in Parameters to reduce lookup

This commit is contained in:
antoniofilipovic
2023-02-02 13:38:41 +01:00
parent 41622cb765
commit b9ae685c48
4 changed files with 31 additions and 32 deletions

View File

@@ -231,7 +231,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
}
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<TypedValue> {
if (index_int >= static_cast<int64_t>(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<double> dif = end - start;
total2 += dif;
// auto end = std::chrono::steady_clock::now();
// std::chrono::duration<double> dif = end - start;
// total2 += dif;
if (total2 > new_print2) {
std::cout << "Time difference visit = " << total2.count() << "[s]" << std::endl;
new_print2 += static_cast<std::chrono::duration<double>>(1.0);
}
// if (total2 > new_print2) {
// std::cout << "Time difference visit = " << total2.count() << "[s]" << std::endl;
// new_print2 += static_cast<std::chrono::duration<double>>(1.0);
// }
return TypedValue(list[index_int]);
}

View File

@@ -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<int, storage::PropertyValue> &At(int position) const {
const storage::PropertyValue &At(int position) const {
MG_ASSERT(position < static_cast<int>(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<std::pair<int, storage::PropertyValue>> storage_;
std::unordered_map<int, storage::PropertyValue> storage_;
};
} // namespace memgraph::query

View File

@@ -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<PropertiesMapList>(&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<double> dif = end - start;
total += dif;
// auto end = std::chrono::steady_clock::now();
// std::chrono::duration<double> 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<std::chrono::duration<double>>(10.0);
}
// if (total > new_print) {
// std::cout << "Time difference props set checked = " << total.count() << "[s]" << std::endl;
// new_print += static_cast<std::chrono::duration<double>>(10.0);
// }
(*frame)[node_info.symbol] = new_node;
return (*frame)[node_info.symbol].ValueVertex();

View File

@@ -212,7 +212,7 @@ Result<std::vector<LabelId>> VertexAccessor::Labels(View view) const {
}
Result<PropertyValue> 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<utils::SpinLock> guard(vertex_->lock);
@@ -233,14 +233,14 @@ Result<PropertyValue> VertexAccessor::SetProperty(PropertyId property, const Pro
UpdateOnSetProperty(indices_, property, value, vertex_, *transaction_);
auto end = std::chrono::steady_clock::now();
std::chrono::duration<double> dif = end - start;
total += dif;
// auto end = std::chrono::steady_clock::now();
// std::chrono::duration<double> dif = end - start;
// total += dif;
if (total > new_print) {
std::cout << "Time difference = " << total.count() << "[s]" << std::endl;
new_print += static_cast<std::chrono::duration<double>>(2.0);
}
// if (total > new_print) {
// std::cout << "Time difference = " << total.count() << "[s]" << std::endl;
// new_print += static_cast<std::chrono::duration<double>>(2.0);
// }
return std::move(current_value);
}