From 77a0ae6acd21f65265120177bf231f5acf0e238e Mon Sep 17 00:00:00 2001 From: Green Sky Date: Mon, 11 Mar 2024 16:26:13 +0100 Subject: [PATCH] fix accel structure being wrong and mark empty frags and dont count them --- src/fragment_store/message_fragment_store.cpp | 64 +++++++++++++++++-- 1 file changed, 57 insertions(+), 7 deletions(-) diff --git a/src/fragment_store/message_fragment_store.cpp b/src/fragment_store/message_fragment_store.cpp index 081090d..49e3f80 100644 --- a/src/fragment_store/message_fragment_store.cpp +++ b/src/fragment_store/message_fragment_store.cpp @@ -71,7 +71,13 @@ namespace Message::Components { namespace Fragment::Components { NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(MessagesTSRange, begin, end) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(MessagesContact, id) -} // Fragment::Components + + namespace Ephemeral { + // does not contain any messges + // (recheck on frag update) + struct MessagesEmptyTag {}; + } +} // Fragment::Component void MessageFragmentStore::handleMessage(const Message3Handle& m) { if (_fs_ignore_event) { @@ -95,6 +101,12 @@ void MessageFragmentStore::handleMessage(const Message3Handle& m) { return; } + // TODO: this is bad, we need a non persistence tag instead + if (!m.any_of()) { + // skip everything else for now + return; + } + // TODO: use fid, seving full fuid for every message consumes alot of memory (and heap frag) if (!m.all_of()) { std::cout << "MFS: new msg missing FID\n"; @@ -273,6 +285,13 @@ void MessageFragmentStore::loadFragment(Message3Registry& reg, FragmentHandle fh if (!j.is_array()) { // wrong data + fh.emplace_or_replace(); + return; + } + + if (j.size() == 0) { + // empty array + fh.emplace_or_replace(); return; } @@ -288,6 +307,7 @@ void MessageFragmentStore::loadFragment(Message3Registry& reg, FragmentHandle fh } reg.ctx().get().frags.emplace(fh); + size_t messages_new_or_updated {0}; for (const auto& j_entry : j) { auto new_real_msg = Message3Handle{reg, reg.create()}; // load into staging reg @@ -339,6 +359,7 @@ void MessageFragmentStore::loadFragment(Message3Registry& reg, FragmentHandle fh // -> merge with preexisting (needs to be order independent) // -> throw update reg.destroy(new_real_msg); + //messages_new_or_updated++; // TODO: how do i know on merging, if data was useful //_rmm.throwEventUpdate(reg, new_real_msg); } else { if (!new_real_msg.all_of()) { @@ -348,10 +369,17 @@ void MessageFragmentStore::loadFragment(Message3Registry& reg, FragmentHandle fh continue; } + messages_new_or_updated++; // -> throw create _rmm.throwEventConstruct(reg, new_real_msg); } } + + if (messages_new_or_updated == 0) { + // useless frag + // TODO: unload? + fh.emplace_or_replace(); + } } bool MessageFragmentStore::syncFragToStorage(FragmentHandle fh, Message3Registry& reg) { @@ -604,6 +632,10 @@ float MessageFragmentStore::tick(float time_delta) { return 0.05f; } + if (fh.all_of()) { + continue; // skip known empty + } + // get ts range of frag and collide with all curser(s/ranges) const auto& [range_begin, range_end] = fh.get(); @@ -654,14 +686,19 @@ float MessageFragmentStore::tick(float time_delta) { // a single adjacent frag is often not enough // only ok bc next is cheap - for (size_t i = 0; i < 5 && _fs._reg.valid(next_frag); i++) { + for (size_t i = 0; i < 5 && _fs._reg.valid(next_frag); next_frag = cf.next(next_frag)) { + auto fh = _fs.fragmentHandle(next_frag); + if (fh.any_of()) { + continue; // skip known empty + } + if (!loaded_frags.contains(next_frag)) { std::cout << "MFS: next frag of range\n"; - loadFragment(*msg_reg, {_fs._reg, next_frag}); + loadFragment(*msg_reg, fh); return 0.05f; } - next_frag = cf.next(next_frag); + i++; } } @@ -697,14 +734,19 @@ float MessageFragmentStore::tick(float time_delta) { // a single adjacent frag is often not enough // only ok bc next is cheap - for (size_t i = 0; i < 5 && _fs._reg.valid(prev_frag); i++) { + for (size_t i = 0; i < 5 && _fs._reg.valid(prev_frag); prev_frag = cf.prev(prev_frag)) { + auto fh = _fs.fragmentHandle(prev_frag); + if (fh.any_of()) { + continue; // skip known empty + } + if (!loaded_frags.contains(prev_frag)) { std::cout << "MFS: prev frag of range\n"; - loadFragment(*msg_reg, {_fs._reg, prev_frag}); + loadFragment(*msg_reg, fh); return 0.05f; } - prev_frag = cf.prev(prev_frag); + i++; } } } @@ -846,6 +888,14 @@ bool Message::Components::ContactFragments::insert(FragmentHandle frag) { frags.emplace(frag, InternalEntry{begin_index, end_index}); + // now adjust all indicies of fragments coming after the insert position + for (size_t i = begin_index + 1; i < sorted_begin.size(); i++) { + frags.at(sorted_begin[i]).i_b = i; + } + for (size_t i = end_index + 1; i < sorted_end.size(); i++) { + frags.at(sorted_end[i]).i_e = i; + } + return true; }