libyang icon indicating copy to clipboard operation
libyang copied to clipboard

enhancement - use a faster hash function for lyht_hash_multi

Open irfanHaslanded opened this issue 11 months ago • 6 comments

Is it possible to switch to a faster hash function such as xxhash or similar? The current implementation of lyht_hash_multi() uses one-at-a-time hash, which may not be the best.

irfanHaslanded avatar Mar 03 '25 17:03 irfanHaslanded

Sure, if you know about a faster hash function, you can measure it and if it performs better, it can be used.

michalvasko avatar Mar 04 '25 08:03 michalvasko

Is it okay to add a dependency to libxxhash-dev or would you prefer to keep the code within libyang, such as xxhash32-ref.c

irfanHaslanded avatar Mar 04 '25 11:03 irfanHaslanded

Seems the package is widely available so it may be fine to keep it as a dependency. But I would like to see some libyang benchmarks before using it.

michalvasko avatar Mar 04 '25 12:03 michalvasko

Created PR here. Do you have anything specific that you would like to test against for benchmarking?

irfanHaslanded avatar Mar 04 '25 14:03 irfanHaslanded

Maybe just 2 basic use-cases, context creation (dictionary hashes) and data tree creation (node hashes). Also, you may want to check what functions to use exactly because our hash function returns uint32_t so 64b hash is redundant.

michalvasko avatar Mar 04 '25 14:03 michalvasko

From the documentation in xxhash.h, it seems like it is okay to XXH3_64bits.

 *   XXH32 is useful for older platforms, with no or poor 64-bit performance.
 *   Note that @ref xxh3_family provides competitive speed
 *   for both 32-bit and 64-bit systems, and offers true 64/128 bit hash results.

irfanHaslanded avatar Mar 04 '25 18:03 irfanHaslanded