From 2b8ba962b80a98c62413c59a189fadacb1985176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Edelbo?= Date: Thu, 19 Oct 2023 13:29:42 +0200 Subject: [PATCH] Optimize further by dropping ttl on ephemeral objects --- src/realm/db.cpp | 10 +++------- src/realm/group.hpp | 14 +------------- src/realm/table.cpp | 12 +++++------- 3 files changed, 9 insertions(+), 27 deletions(-) diff --git a/src/realm/db.cpp b/src/realm/db.cpp index 77b35f8f498..cfc53ec54ae 100644 --- a/src/realm/db.cpp +++ b/src/realm/db.cpp @@ -2412,15 +2412,11 @@ Replication::version_type DB::do_commit(Transaction& transaction, bool commit_to version_type new_version = current_version + 1; if (!transaction.m_objects_to_delete.empty()) { - std::map> table_object_map; - for (auto it : transaction.m_objects_to_delete) { - // Checking ttl would go here - table_object_map[it.table_key].push_back(it.obj_key); + for (auto& [table_key, obj_keys] : transaction.m_objects_to_delete) { + sort(obj_keys.begin(), obj_keys.end()); + transaction.get_table_unchecked(table_key)->batch_erase_objects(obj_keys); } transaction.m_objects_to_delete.clear(); - for (auto& item : table_object_map) { - transaction.get_table_unchecked(item.first)->batch_erase_objects(item.second); - } } if (Replication* repl = get_replication()) { // If Replication::prepare_commit() fails, then the entire transaction diff --git a/src/realm/group.hpp b/src/realm/group.hpp index 0501742aed6..3b7e1ed8b7e 100644 --- a/src/realm/group.hpp +++ b/src/realm/group.hpp @@ -538,18 +538,6 @@ class Group : public ArrayParent { private: static constexpr StringData g_class_name_prefix = "class_"; - struct ToDeleteRef { - ToDeleteRef(TableKey tk, ObjKey k) - : table_key(tk) - , obj_key(k) - , ttl(std::chrono::steady_clock::now()) - { - } - TableKey table_key; - ObjKey obj_key; - std::chrono::steady_clock::time_point ttl; - }; - // nullptr, if we're sharing an allocator provided during initialization std::unique_ptr m_local_alloc; // in-use allocator. If local, then equal to m_local_alloc. @@ -614,7 +602,7 @@ class Group : public ArrayParent { util::UniqueFunction m_notify_handler; util::UniqueFunction m_schema_change_handler; - std::vector m_objects_to_delete; + std::map> m_objects_to_delete; Group(SlabAlloc* alloc) noexcept; void init_array_parents() noexcept; diff --git a/src/realm/table.cpp b/src/realm/table.cpp index 0f1fbed31ae..73afcec9230 100644 --- a/src/realm/table.cpp +++ b/src/realm/table.cpp @@ -3056,7 +3056,7 @@ Obj Table::create_object_with_primary_key(const Mixed& primary_key, FieldValues& } } if (is_asymmetric() && repl && repl->get_history_type() == Replication::HistoryType::hist_SyncClient) { - get_parent_group()->m_objects_to_delete.emplace_back(this->m_key, ret.get_key()); + get_parent_group()->m_objects_to_delete[this->m_key].emplace_back(ret.get_key()); } return ret; } @@ -3391,12 +3391,10 @@ void Table::remove_object(ObjKey key) if (is_asymmetric()) { REALM_ASSERT(g); - auto it = std::find_if(g->m_objects_to_delete.begin(), g->m_objects_to_delete.end(), - [&](const Group::ToDeleteRef& item) { - return item.table_key == m_key && item.obj_key == key; - }); - if (it != g->m_objects_to_delete.end()) { - g->m_objects_to_delete.erase(it); + auto& obj_keys = g->m_objects_to_delete[m_key]; + auto it = std::find(obj_keys.begin(), obj_keys.end(), key); + if (it != obj_keys.end()) { + obj_keys.erase(it); } }