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

Use early return to clean up ClientImplBase::Session::send_message() #4908

Merged
merged 2 commits into from Sep 23, 2021

Conversation

RedBeard0531
Copy link
Contributor

This should be identical to the original version, just easier to read.

What, How & Why?

☑️ ToDos

  • [ ] 📝 Changelog update
  • [ ] 🚦 Tests (or not relevant)

This should be identical to the original version, just easier to read.
REALM_ASSERT(m_upload_progress.client_version <= m_upload_target_version);
REALM_ASSERT(m_upload_target_version <= m_last_version_available);
bool need_upload = (m_upload_target_version > m_upload_progress.client_version);
if (REALM_UNLIKELY(need_upload) && REALM_LIKELY(m_allow_upload))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I know that this means that it is UNLIKELY that we will do anything at all in this function. That seems incorrect, but does match the old code 🤷

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we think that all these LIKELY hints are helping us? At the very least, I don't think we can know whether this is likely or unlikely and would be included to remove this hint.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway - I would assume that this code is not super performance critical, so are these hints more noisy than helpful?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to remove that nonsense. I'll update the patch on Wednesday

}
}
else {
if (REALM_UNLIKELY(m_deactivation_initiated) || REALM_UNLIKELY(m_error_message_received)) {
// Deactivation has been initiated. If the UNBIND message has not been
// sent yet, there is no point in sending it. Instead, we can let the
// deactivation process complete.
if (!m_bind_message_sent) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a slight change from the old code, we will evaluate this condition when m_deactivation_initiated is false, and m_error_message_received is true. However, there is no behavior change since if m_error_message_received is true, m_bind_message_sent must also be true, so we never enter this if block. See

bool legal_at_this_time = (m_bind_message_sent && !m_error_message_received && !m_unbound_message_received);
if (REALM_UNLIKELY(!legal_at_this_time)) {
logger.error("Illegal message at this time");
return ClientError::bad_message_order;
}
bool known_error_code = bool(sync::get_protocol_error_message(error_code));
if (REALM_UNLIKELY(!known_error_code)) {
logger.error("Unknown error code"); // Throws
return ClientError::bad_error_code;
}
ProtocolError error_code_2 = ProtocolError(error_code);
if (REALM_UNLIKELY(!is_session_level_error(error_code_2))) {
logger.error("Not a session level error code"); // Throws
return ClientError::bad_error_code;
}
REALM_ASSERT(!m_suspended);
REALM_ASSERT(m_active_or_deactivating);
logger.debug("Suspended"); // Throws
m_error_message_received = true;
.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@RedBeard0531 RedBeard0531 marked this pull request as ready for review September 17, 2021 09:54
Copy link
Contributor

@jbreams jbreams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great.

REALM_ASSERT(m_upload_progress.client_version <= m_upload_target_version);
REALM_ASSERT(m_upload_target_version <= m_last_version_available);
bool need_upload = (m_upload_target_version > m_upload_progress.client_version);
if (REALM_UNLIKELY(need_upload) && REALM_LIKELY(m_allow_upload))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we think that all these LIKELY hints are helping us? At the very least, I don't think we can know whether this is likely or unlikely and would be included to remove this hint.

}
}
else {
if (REALM_UNLIKELY(m_deactivation_initiated) || REALM_UNLIKELY(m_error_message_received)) {
// Deactivation has been initiated. If the UNBIND message has not been
// sent yet, there is no point in sending it. Instead, we can let the
// deactivation process complete.
if (!m_bind_message_sent) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@RedBeard0531 RedBeard0531 merged commit 847aabc into master Sep 23, 2021
@RedBeard0531 RedBeard0531 deleted the ms/sync_cleanup branch September 23, 2021 12:14
dianaafanador3 pushed a commit that referenced this pull request Oct 27, 2021
…4908)

This should be identical to the original version, just easier to read.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants