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

Add query & queryable token config #260

Merged
merged 16 commits into from
Oct 13, 2023

Conversation

jean-roland
Copy link
Contributor

@jean-roland jean-roland commented Oct 11, 2023

This adds compile time config tokens to add or remove queries & queryables independently. The measured impact on program memory was, if you look at the sum of the symbol sizes from the Z_pub example elf, in O3 on amd64 linux:

  • Full feature: 127 685B
  • No queryable: 124 353B (-3332, 2.6%)
  • No query & queryable: 120 087B (-4266, 3.4%)

Copy link
Member

@cguimaraes cguimaraes left a comment

Choose a reason for hiding this comment

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

If the purpose is to make the final binary smaller, see inline comments.

Also, it was always a mindset in Zenoh team that errors or incompatibilities to be explicit to the user (preferable at compilation time, instead of runtime). Then, I suggest that if queries /queryables are disable that the corresponding API is also ommited.

src/api/api.c Outdated
@@ -654,14 +657,17 @@ typedef struct __z_reply_handler_wrapper_t {
} __z_reply_handler_wrapper_t;

void __z_reply_handler(_z_reply_t *reply, __z_reply_handler_wrapper_t *wrapped_ctx) {
Copy link
Member

Choose a reason for hiding this comment

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

If queries are not supported, the entire reply handler can be ommitted.

src/api/api.c Outdated
z_owned_reply_t oreply = {._value = reply};

wrapped_ctx->user_call(&oreply, wrapped_ctx->ctx);
z_reply_drop(&oreply); // user_call is allowed to take ownership of the reply by setting oreply._value to NULL
#endif
}

int8_t z_get(z_session_t zs, z_keyexpr_t keyexpr, const char *parameters, z_owned_closure_reply_t *callback,
Copy link
Member

Choose a reason for hiding this comment

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

If queries are disabled, I would completely omit any related APIs.

In doing so, the user will have an explicit error at compilation. Otherwise, it will become harder for users (and us) to debug non-compliant behavior.

Also, you can save some extra bytes in the final binary.

src/api/api.c Outdated
@@ -896,6 +905,7 @@ z_queryable_options_t z_queryable_options_default(void) {

z_owned_queryable_t z_declare_queryable(z_session_t zs, z_keyexpr_t keyexpr, z_owned_closure_query_t *callback,
Copy link
Member

Choose a reason for hiding this comment

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

If queryables are disabled, I would completely omit any related APIs.

In doing so, the user will have an explicit error at compilation. Otherwise, it will become harder for users (and us) to debug non-compliant behavior.

Also, you can save some extra bytes in the final binary.

src/api/api.c Outdated
@@ -923,14 +933,20 @@ z_owned_queryable_t z_declare_queryable(z_session_t zs, z_keyexpr_t keyexpr, z_o

return (z_owned_queryable_t){
._value = _z_declare_queryable(zs._val, key, opt.complete, callback->call, callback->drop, ctx)};
#else
return (z_owned_queryable_t){._value = NULL};
#endif
}

int8_t z_undeclare_queryable(z_owned_queryable_t *queryable) {
Copy link
Member

Choose a reason for hiding this comment

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

If queryables are disabled, I would completely omit any related APIs.

In doing so, the user will have an explicit error at compilation. Otherwise, it will become harder for users (and us) to debug non-compliant behavior.

Also, you can save some extra bytes in the final binary.

src/api/api.c Outdated
@@ -940,6 +956,7 @@ z_query_reply_options_t z_query_reply_options_default(void) {

int8_t z_query_reply(const z_query_t *query, const z_keyexpr_t keyexpr, const uint8_t *payload, size_t payload_len,
const z_query_reply_options_t *options) {
Copy link
Member

Choose a reason for hiding this comment

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

If queryables are disabled, I would completely omit any related APIs.

In doing so, the user will have an explicit error at compilation. Otherwise, it will become harder for users (and us) to debug non-compliant behavior.

Also, you can save some extra bytes in the final binary.

src/api/api.c Outdated
@@ -949,6 +966,9 @@ int8_t z_query_reply(const z_query_t *query, const z_keyexpr_t keyexpr, const ui
},
.encoding = {.prefix = opts.encoding.prefix, .suffix = opts.encoding.suffix}};
return _z_send_reply(query, keyexpr, value);
#else
return _Z_ERR_GENERIC;
#endif
}

_Bool z_reply_is_ok(const z_owned_reply_t *reply) {
Copy link
Member

Choose a reason for hiding this comment

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

If queryables are disabled, I would completely omit any related APIs.

In doing so, the user will have an explicit error at compilation. Otherwise, it will become harder for users (and us) to debug non-compliant behavior.

Also, you can save some extra bytes in the final binary.

src/session/rx.c Outdated
@@ -154,9 +162,13 @@ int8_t _z_handle_network_message(_z_session_t *zn, _z_zenoh_message_t *msg, uint
}
} break;
case _Z_N_RESPONSE_FINAL: {
#if Z_FEATURE_QUERIES == 1
Copy link
Member

Choose a reason for hiding this comment

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

Response and ResponseFinal are not limited to queries/queryables.

@jean-roland
Copy link
Contributor Author

jean-roland commented Oct 13, 2023

Here are the modifications on the update:

  • APIs were removed, this breaks examples compilation so for the moment being I replace the affected examples with a dummy main when necessary
  • I tried to regroup the feature code to reduce #if directives as they make code harder to read
  • I added some feature-agnostic "reply" and "push" functions

The changes slightly enhanced the size reduction:

  • No queryable: 124 045B (-308B, 0.25%)
  • No query & queryable: 119 669B (-418B, 0.35%)

Copy link
Member

@cguimaraes cguimaraes left a comment

Choose a reason for hiding this comment

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

LGTM. A couple of comments only.

#ifndef ZENOH_PICO_SESSION_REPLY_H
#define ZENOH_PICO_SESSION_REPLY_H

int8_t _z_trigger_reply_partial(_z_session_t *zn, _z_zint_t id, _z_keyexpr_t key, _z_msg_reply_t *reply);
Copy link
Member

Choose a reason for hiding this comment

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

Check for the features here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The overarching goal here, as mentioned by @Mallets, is to dissociate replies with requests as in the future there might be reply packets for other features.

Same for push packet and subscriptions.

#if Z_FEATURE_QUERY == 1
ret = _z_trigger_query_reply_partial(zn, id, key, reply->_value.payload, reply->_value.encoding, Z_SAMPLE_KIND_PUT,
reply->_timestamp);
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Return error if not supported?


#if Z_FEATURE_QUERY == 1
_z_trigger_query_reply_final(zn, id);
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Return error if not supported?

cguimaraes
cguimaraes previously approved these changes Oct 13, 2023
@cguimaraes cguimaraes dismissed their stale review October 13, 2023 13:18

My main comments were addressed. @p-avital or @Mallets for the final approval.

@Mallets Mallets merged commit dd8b943 into eclipse-zenoh:master Oct 13, 2023
27 checks passed
@jean-roland jean-roland deleted the ft_query_token_config branch October 20, 2023 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants