From 54066f338f185f2fbd6694d9a4877f42cbfa21c8 Mon Sep 17 00:00:00 2001 From: iphydf Date: Thu, 9 Aug 2018 23:53:39 +0000 Subject: Reduce the number of times `unix_time_update` is called. Reduced by, e.g.: * `file_transfer_test`: 33% of the `clock_gettime` calls. * `tox_many_test`: 53% of the `clock_gettime` calls. Other tests will see similar improvements. Real world applications will be closer to 40-50% improvement, since tox_many_test has 100 nodes, while file_transfer_test has 2 nodes. --- toxcore/DHT.c | 9 --------- toxcore/Messenger.c | 2 -- toxcore/TCP_client.c | 2 -- toxcore/TCP_server.c | 2 -- toxcore/net_crypto.c | 3 --- toxcore/network.c | 2 -- toxcore/tox.c | 5 +++++ 7 files changed, 5 insertions(+), 20 deletions(-) (limited to 'toxcore') diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 37dd9385..94928b75 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -2690,9 +2690,6 @@ static int cryptopacket_handle(void *object, IP_Port source, const uint8_t *pack DHT *new_dht(const Logger *log, Networking_Core *net, bool holepunching_enabled) { - /* init time */ - unix_time_update(); - if (net == nullptr) { return nullptr; } @@ -2741,8 +2738,6 @@ DHT *new_dht(const Logger *log, Networking_Core *net, bool holepunching_enabled) void do_dht(DHT *dht) { - unix_time_update(); - if (dht->last_run == unix_time()) { return; } @@ -2963,8 +2958,6 @@ int dht_load(DHT *dht, const uint8_t *data, uint32_t length) */ bool dht_isconnected(const DHT *dht) { - unix_time_update(); - for (uint32_t i = 0; i < LCLIENT_LIST; ++i) { const Client_data *const client = &dht->close_clientlist[i]; @@ -2982,8 +2975,6 @@ bool dht_isconnected(const DHT *dht) */ bool dht_non_lan_connected(const DHT *dht) { - unix_time_update(); - for (uint32_t i = 0; i < LCLIENT_LIST; ++i) { const Client_data *const client = &dht->close_clientlist[i]; diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index acf9f806..ab341e61 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -2603,8 +2603,6 @@ void do_messenger(Messenger *m, void *userdata) } } - unix_time_update(); - if (!m->options.udp_disabled) { networking_poll(m->net, userdata); do_dht(m->dht); diff --git a/toxcore/TCP_client.c b/toxcore/TCP_client.c index 381d9b80..d6a27c95 100644 --- a/toxcore/TCP_client.c +++ b/toxcore/TCP_client.c @@ -985,8 +985,6 @@ static int do_confirmed_TCP(TCP_Client_Connection *conn, void *userdata) */ void do_TCP_connection(TCP_Client_Connection *tcp_connection, void *userdata) { - unix_time_update(); - if (tcp_connection->status == TCP_CLIENT_DISCONNECTED) { return; } diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c index cc59d088..207a5107 100644 --- a/toxcore/TCP_server.c +++ b/toxcore/TCP_server.c @@ -1424,8 +1424,6 @@ static void do_TCP_epoll(TCP_Server *tcp_server) void do_TCP_server(TCP_Server *tcp_server) { - unix_time_update(); - #ifdef TCP_SERVER_USE_EPOLL do_TCP_epoll(tcp_server); diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 8f5fd507..bd214b91 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c @@ -2925,8 +2925,6 @@ void load_secret_key(Net_Crypto *c, const uint8_t *sk) */ Net_Crypto *new_net_crypto(const Logger *log, DHT *dht, TCP_Proxy_Info *proxy_info) { - unix_time_update(); - if (dht == nullptr) { return nullptr; } @@ -3016,7 +3014,6 @@ uint32_t crypto_run_interval(const Net_Crypto *c) /* Main loop. */ void do_net_crypto(Net_Crypto *c, void *userdata) { - unix_time_update(); kill_timedout(c, userdata); do_tcp(c, userdata); send_crypto_packets(c); diff --git a/toxcore/network.c b/toxcore/network.c index 68ca43e5..08bec13a 100644 --- a/toxcore/network.c +++ b/toxcore/network.c @@ -641,8 +641,6 @@ void networking_poll(Networking_Core *net, void *userdata) return; } - unix_time_update(); - IP_Port ip_port; uint8_t data[MAX_UDP_PACKET_SIZE]; uint32_t length; diff --git a/toxcore/tox.c b/toxcore/tox.c index cd1b71f0..879b5c09 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -38,6 +38,7 @@ #include "Messenger.h" #include "group.h" #include "logger.h" +#include "mono_time.h" #include "../toxencryptsave/defines.h" @@ -335,6 +336,8 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error) return nullptr; } + unix_time_update(); + Messenger_Options m_options = {0}; bool load_savedata_sk = false, load_savedata_tox = false; @@ -653,6 +656,8 @@ uint32_t tox_iteration_interval(const Tox *tox) void tox_iterate(Tox *tox, void *user_data) { + unix_time_update(); + Messenger *m = tox->m; struct Tox_Userdata tox_data = { tox, user_data }; do_messenger(m, &tox_data); -- cgit v1.2.3