Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RCORE-2064 String EQ/NEQ optimisations for compressed strings #7820

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
71a2318
No unique ptrs for string interner + limit number of interners
nicola-cab Jun 12, 2024
7265c53
point fix client-reset test
nicola-cab Jun 13, 2024
219dbef
minor stuff
nicola-cab Jun 13, 2024
aec41a1
string compression tests
nicola-cab Jun 14, 2024
59e1a5a
Merge branch 'feature/string-compression' of github.com:realm/realm-c…
nicola-cab Jun 17, 2024
2e7f996
Merge branch 'feature/string-compression' of github.com:realm/realm-c…
nicola-cab Jun 17, 2024
2c45256
point fix check string ids + more tests
nicola-cab Jun 17, 2024
b27b52e
new node addition failure for string interner
nicola-cab Jun 17, 2024
7b8ffe7
point fix lookup compressed string id when rehashing
nicola-cab Jun 18, 2024
4d573e1
find_first optimization for compressed strings
nicola-cab Jun 18, 2024
ad2cfa4
Merge branch 'nc/string_interner_tests' into nc/eq_neq_string_compres…
nicola-cab Jun 18, 2024
50a9287
Merge branch 'feature/string-compression' of github.com:realm/realm-c…
nicola-cab Jun 19, 2024
71b34ed
core test passing
nicola-cab Jun 18, 2024
264aae4
compression tests for collection of strings
nicola-cab Jun 19, 2024
050fb75
Merge branch 'nc/string_interner_tests' into nc/eq_neq_string_compres…
nicola-cab Jun 19, 2024
508bbb7
code review
nicola-cab Jul 5, 2024
eedfa69
Merge branch 'feature/string-compression' of github.com:realm/realm-c…
nicola-cab Jul 8, 2024
9653f0f
Fixes (#7872)
jedelbo Jul 10, 2024
057a46c
Merge branch 'feature/string-compression' into nc/eq_neq_string_compr…
jedelbo Jul 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/realm/array_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ size_t ArrayString::find_first(StringData value, size_t begin, size_t end, std::
if (id) {
return static_cast<Array*>(m_arr)->find_first(*id, begin, end);
}
nicola-cab marked this conversation as resolved.
Show resolved Hide resolved
break;
}
default:
break;
Expand Down
6 changes: 1 addition & 5 deletions src/realm/query_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,7 @@ bool StringNode<Equal>::do_consume_condition(ParentNode& node)
size_t StringNode<Equal>::_find_first_local(size_t start, size_t end)
{
if (m_needles.empty()) {
if (m_interned_string)
return m_leaf->find_first(m_string_value, start, end, m_interned_string);
else
return m_leaf->find_first(m_string_value, start, end);
return m_leaf->find_first(m_string_value, start, end);
nicola-cab marked this conversation as resolved.
Show resolved Hide resolved
}
else {
if (end == npos)
Expand Down Expand Up @@ -519,7 +516,6 @@ StringNodeFulltext::StringNodeFulltext(StringData v, ColKey column, std::unique_

void StringNodeFulltext::table_changed()
{
StringNodeEqualBase::table_changed();
m_link_map->set_base_table(m_table);
}

Expand Down
4 changes: 1 addition & 3 deletions src/realm/query_engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1591,9 +1591,7 @@ class StringNodeBase : public ParentNode {
{
m_is_string_enum = m_table.unchecked_ptr()->is_enumerated(m_condition_column_key);
m_string_interner = m_table.unchecked_ptr()->get_string_interner(m_condition_column_key);
if (m_string_interner) {
m_interned_string = m_string_interner->lookup(m_value);
}
m_interned_string = m_string_interner->lookup(m_value);
}

void cluster_changed() override
Expand Down
38 changes: 4 additions & 34 deletions src/realm/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1765,36 +1765,6 @@ ObjKey Table::find_first(ColKey col_key, T value) const
using LeafType = typename ColumnTypeTraits<T>::cluster_leaf_type;
LeafType leaf(get_alloc());

nicola-cab marked this conversation as resolved.
Show resolved Hide resolved
// there might be an interner for this column key. In case there is, and the string is compressed,
// we can extract the string id and use it while we scan the leaf values (the ids are just integers,
// so searching should be faster)
std::optional<StringID> string_id;
if constexpr (std::is_same_v<T, StringData>) {
if (const auto string_interner = get_string_interner(col_key); string_interner != nullptr) {
string_id = string_interner->lookup(value);

auto f = [&key, &col_key, &value, &leaf, &string_id](const Cluster* cluster) {
cluster->init_leaf(col_key, &leaf);

size_t row;
if (string_id)
row = leaf.find_first(value, 0, cluster->node_size(), string_id);
else
row = leaf.find_first(value, 0, cluster->node_size());

if (row != realm::npos) {
key = cluster->get_real_key(row);
return IteratorControl::Stop;
}
return IteratorControl::AdvanceToNext;
};

traverse_clusters(f);

return key;
}
}

auto f = [&key, &col_key, &value, &leaf](const Cluster* cluster) {
cluster->init_leaf(col_key, &leaf);
size_t row = leaf.find_first(value, 0, cluster->node_size());
Expand Down Expand Up @@ -3560,8 +3530,8 @@ void Table::typed_print(std::string prefix, ref_type ref) const

StringInterner* Table::get_string_interner(ColKey::Idx idx) const
{
const auto index = idx.val;
if (index < m_string_interners.size())
return m_string_interners[index].get();
return nullptr;
REALM_ASSERT(idx.val < m_string_interners.size());
auto interner = m_string_interners[idx.val].get();
REALM_ASSERT(interner);
return interner;
}
Loading