Skip to content

Commit

Permalink
Optimize further by dropping ttl on ephemeral objects
Browse files Browse the repository at this point in the history
  • Loading branch information
jedelbo committed Oct 19, 2023
1 parent 1042cef commit 2b8ba96
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 27 deletions.
10 changes: 3 additions & 7 deletions src/realm/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<TableKey, std::vector<ObjKey>> 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());

This comment has been minimized.

Copy link
@danieltabacaru

danieltabacaru Oct 19, 2023

Collaborator

is this an optimization?

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
Expand Down
14 changes: 1 addition & 13 deletions src/realm/group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<SlabAlloc> m_local_alloc;
// in-use allocator. If local, then equal to m_local_alloc.
Expand Down Expand Up @@ -614,7 +602,7 @@ class Group : public ArrayParent {

util::UniqueFunction<void(const CascadeNotification&)> m_notify_handler;
util::UniqueFunction<void()> m_schema_change_handler;
std::vector<ToDeleteRef> m_objects_to_delete;
std::map<TableKey, std::vector<ObjKey>> m_objects_to_delete;

Group(SlabAlloc* alloc) noexcept;
void init_array_parents() noexcept;
Expand Down
12 changes: 5 additions & 7 deletions src/realm/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 2b8ba96

Please sign in to comment.