Skip to content

Commit

Permalink
improve trigger queryables performance
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisBiryukov91 committed Mar 3, 2025
1 parent 5f98235 commit 88d4b31
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
42 changes: 22 additions & 20 deletions src/session/queryable.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,19 @@ static z_result_t _z_trigger_queryables_inner(_z_session_rc_t *zsrc, _z_msg_quer
uint32_t qid) {
_z_session_t *zn = _Z_RC_IN_VAL(zsrc);
_z_queryable_cache_data_t qle_infos = _z_queryable_cache_data_null();
qle_infos.ke_in = _z_keyexpr_alias(q_key);
qle_infos.ke_in = _z_keyexpr_steal(q_key);
// Retrieve sub infos
_Z_RETURN_IF_ERR(_z_session_queryable_get_infos(zn, &qle_infos));
_Z_CLEAN_RETURN_IF_ERR(_z_session_queryable_get_infos(zn, &qle_infos), _z_keyexpr_clear(&qle_infos.ke_in);
_z_value_clear(&msgq->_ext_value); _z_bytes_drop(&msgq->_ext_attachment);
_z_slice_clear(&msgq->_parameters););
// Check if there are queryables
_Z_DEBUG("Triggering %ju queryables for key %d - %.*s", (uintmax_t)qle_infos.qle_nb, qle_infos.ke_out._id,
(int)_z_string_len(&qle_infos.ke_out._suffix), _z_string_data(&qle_infos.ke_out._suffix));
if (qle_infos.qle_nb == 0) {
_z_keyexpr_clear(&qle_infos.ke_in);
_z_value_clear(&msgq->_ext_value);
_z_bytes_drop(&msgq->_ext_attachment);
_z_slice_clear(&msgq->_parameters);
_z_keyexpr_clear(&qle_infos.ke_out);
#if Z_FEATURE_RX_CACHE == 0
_z_queryable_infos_svec_release(&qle_infos.infos); // Otherwise it's released with cache
Expand Down Expand Up @@ -238,34 +244,30 @@ static z_result_t _z_trigger_queryables_inner(_z_session_rc_t *zsrc, _z_msg_quer

z_result_t ret = _Z_RES_OK;
// Parse session_queryable svec
for (size_t i = 1; i < qle_infos.qle_nb; i++) {
_z_query_rc_t query_copy;
ret = _z_query_rc_copy(&query_copy, &query);
if (ret != _Z_RES_OK) {
break;
}
for (size_t i = 0; i < qle_infos.qle_nb; i++) {
_z_queryable_infos_t *qle_info = _z_queryable_infos_svec_get(&qle_infos.infos, i);
qle_info->callback(&query_copy, qle_info->arg);
_z_query_rc_drop(&query_copy);
if (i + 1 == qle_infos.qle_nb) {
qle_info->callback(&query, qle_info->arg);
} else {
_z_query_rc_t query_copy;
ret = _z_query_rc_copy(&query_copy, &query);
if (ret != _Z_RES_OK) {
break;
}
qle_info->callback(&query_copy, qle_info->arg);
_z_query_rc_drop(&query_copy);
}
}

_z_queryable_infos_t *qle_info = _z_queryable_infos_svec_get(&qle_infos.infos, 0);
qle_info->callback(&query, qle_info->arg);
_z_query_rc_drop(&query);
#if Z_FEATURE_RX_CACHE == 0
_z_queryable_infos_svec_release(&qle_infos.infos); // Otherwise it's released with cache
#endif
_z_keyexpr_clear(&qle_infos.ke_in);
return ret;
}

z_result_t _z_trigger_queryables(_z_session_rc_t *zsrc, _z_msg_query_t *msgq, _z_keyexpr_t *q_key, uint32_t qid) {
z_result_t ret = _z_trigger_queryables_inner(zsrc, msgq, q_key, qid);
// Clean up
_z_keyexpr_clear(q_key);
_z_value_clear(&msgq->_ext_value);
_z_bytes_drop(&msgq->_ext_attachment);
_z_slice_clear(&msgq->_parameters);
return ret;
return _z_trigger_queryables_inner(zsrc, msgq, q_key, qid);
}

void _z_unregister_session_queryable(_z_session_t *zn, _z_session_queryable_rc_t *qle) {
Expand Down
5 changes: 2 additions & 3 deletions src/session/subscription.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,9 @@ static z_result_t _z_trigger_subscriptions_inner(_z_session_t *zn, _z_subscriber
}
_z_sample_clear(&sample);
#if Z_FEATURE_RX_CACHE == 0
_z_subscription_infos_svec_release(&sub_infos.infos);
#else
_z_keyexpr_clear(&sub_infos.ke_in);
_z_subscription_infos_svec_release(&sub_infos.infos); // Otherwise it's released with cache
#endif
_z_keyexpr_clear(&sub_infos.ke_in);
return ret;
}

Expand Down

0 comments on commit 88d4b31

Please sign in to comment.