-
Notifications
You must be signed in to change notification settings - Fork 163
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
Optimize size of Node and Array #7992
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,16 +41,13 @@ void Spec::init(MemRef mem) noexcept | |
{ | ||
m_top.init_from_mem(mem); | ||
size_t top_size = m_top.size(); | ||
REALM_ASSERT(top_size > s_attributes_ndx && top_size <= s_spec_max_size); | ||
// Since Core6 we will always have the column keys array | ||
REALM_ASSERT(top_size == s_spec_max_size); | ||
|
||
m_types.init_from_ref(m_top.get_as_ref(s_types_ndx)); | ||
m_names.init_from_ref(m_top.get_as_ref(s_names_ndx)); | ||
m_attr.init_from_ref(m_top.get_as_ref(s_attributes_ndx)); | ||
|
||
while (m_top.size() < s_spec_max_size) { | ||
m_top.add(0); | ||
} | ||
|
||
// Enumkeys array is only there when there are StringEnum columns | ||
if (auto ref = m_top.get_as_ref(s_enum_keys_ndx)) { | ||
m_enumkeys.init_from_ref(ref); | ||
|
@@ -59,34 +56,22 @@ void Spec::init(MemRef mem) noexcept | |
m_enumkeys.detach(); | ||
} | ||
|
||
if (m_top.get_as_ref(s_col_keys_ndx) == 0) { | ||
// This is an upgrade - create column key array | ||
MemRef mem_ref = Array::create_empty_array(Array::type_Normal, false, m_top.get_alloc()); // Throws | ||
m_keys.init_from_mem(mem_ref); | ||
m_keys.update_parent(); | ||
size_t num_cols = m_types.size(); | ||
for (size_t i = 0; i < num_cols; i++) { | ||
m_keys.add(i); | ||
} | ||
} | ||
else { | ||
m_keys.init_from_parent(); | ||
} | ||
|
||
m_keys.init_from_parent(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consider adding an assertion that m_top.get_as_ref(s_col_keys_ndx) is not zero (not blocking) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, we don't check the other entries and I am sure we will have an assertion down the line if the ref is zero. |
||
|
||
update_internals(); | ||
} | ||
|
||
void Spec::update_internals() noexcept | ||
{ | ||
m_num_public_columns = 0; | ||
size_t n = m_types.size(); | ||
for (size_t i = 0; i < n; ++i) { | ||
if (ColumnType(int(m_types.get(i))) == col_type_BackLink) { | ||
// Now we have no more public columns | ||
m_num_public_columns = n; | ||
// We normally have fewer backlink columns than public columns, so quicker to go backwards | ||
for (size_t i = n; i; --i) { | ||
if (ColumnType(int(m_types.get(i - 1))) != col_type_BackLink) { | ||
// Now we have no more backlink columns. The rest must be public | ||
return; | ||
} | ||
m_num_public_columns++; | ||
m_num_public_columns--; | ||
} | ||
} | ||
|
||
|
@@ -207,8 +192,6 @@ void Spec::insert_column(size_t column_ndx, ColKey col_key, ColumnType type, Str | |
if (m_enumkeys.is_attached() && type != col_type_BackLink) { | ||
m_enumkeys.insert(column_ndx, 0); | ||
} | ||
|
||
update_internals(); | ||
} | ||
|
||
void Spec::erase_column(size_t column_ndx) | ||
|
@@ -246,8 +229,6 @@ void Spec::erase_column(size_t column_ndx) | |
m_types.erase(column_ndx); // Throws | ||
m_attr.erase(column_ndx); // Throws | ||
m_keys.erase(column_ndx); | ||
|
||
update_internals(); | ||
} | ||
|
||
void Spec::upgrade_string_to_enum(size_t column_ndx, ref_type keys_ref) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears that this case should never happen, should we have a REALM_UNREACHABLE here?