Problem:
My point is there are a lot of cases where the returned by telegram response isn't fully needed - therefore, avoiding its deserialization or deserializing upon the request can speed up the process significantly.
For example, consider sending the message to some chat with auto resp = api::send_message(connector, args);
,
where API can return the following JSON -
{"ok":true,"result":{"message_id":1197,"from":{"id":..,"is_bot":true,"first_name":"Fun Bot","username":"..."},"chat":{"id":..,"title":"simulation","type":"supergroup"},"date":1623916598,"text":"Hello, world!"}}
What banana does, is deserializing the whole returned JSON into message_t
, which is relatively slow, because, in fact, only "ok": true, "result":{}
can be significant for the end client.
Solution:
My suggestion here is to do partial deserialization of the ok, result
fields - similarly to what we can see in the extract_api_result
, but parsing certain depth only and postpone the whole deserialization:
Provide a way to receive status-only responses or do lazy-like deserialization;
auto ok_resp = api::send_message(connector, args, /*lazy=*/true); // by default, lazy = false
if (!ok_resp) { // ok = false or error happened }
else {
cout << string(ok_resp) << "\n"; // json response printed
process(*ok_resp); // here the whole deserialization happens - we might not even call this
}
Let me know your thoughts about such a proposal.
enhancement agent api