diff options
author | Eric Wong <e@80x24.org> | 2022-11-20 09:55:20 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2022-12-02 09:40:01 +0000 |
commit | 021a1d6ec4865653ac5c265cbc55269b37e3b59f (patch) | |
tree | c9625c8af76ff0b79f3bdd08911966128b98dfa5 | |
parent | e20367559b8bd677b7386818cb8a672b003f2e25 (diff) | |
download | mwrap-021a1d6ec4865653ac5c265cbc55269b37e3b59f.tar.gz |
This seems to provide a 2% speedup or so in my test case compared to jhash, but we are only picking 32 of the 64 output bits from XXH3_64bits. Using the 32-bit XXH32 variant did not show any measurable improvement over jhash.
-rw-r--r-- | Makefile.PL | 12 | ||||
-rw-r--r-- | mwrap_core.h | 27 |
2 files changed, 38 insertions, 1 deletions
diff --git a/Makefile.PL b/Makefile.PL index 7ea7929..eab1edb 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -31,6 +31,17 @@ END # may be empty chomp(my $INC = `$pkg_config --cflags liburcu-cds liburcu-bp`); my @writemakefile_args = (); +my $ccflags = ''; + +print '# checking libxxhash... '; +chomp(my $xxhash_inc = `$pkg_config --cflags libxxhash`); +if ($? == 0) { + $INC .= " $xxhash_inc"; + $ccflags .= ' -DHAVE_XXHASH'; + say 'yes'; +} else { + say 'no'; +} use IO::Handle; STDOUT->autoflush(1); @@ -68,6 +79,7 @@ say " no on $^O" if $@; push @writemakefile_args, ( NAME => 'Devel::Mwrap', VERSION_FROM => 'lib/Devel/Mwrap.pm', + CCFLAGS => "$Config{ccflags} $ccflags", PREREQ_PM => {}, ABSTRACT_FROM => 'lib/Devel/Mwrap.pm', EXE_FILES => [qw(script/mwrap-perl)], diff --git a/mwrap_core.h b/mwrap_core.h index f3b25b7..dab3e77 100644 --- a/mwrap_core.h +++ b/mwrap_core.h @@ -46,7 +46,23 @@ #include <urcu-bp.h> #include <urcu/rculfhash.h> #include <urcu/rculist.h> -#include "jhash.h" + +/* + * XXH3 (truncated to 32-bits) seems to provide a ~2% speedup. + * XXH32 doesn't show improvements over jhash despite rculfhash + * only supporting 32-bit hash values. + */ +#if defined(HAVE_XXHASH) +# define XXH_INLINE_ALL +# include <xxhash.h> +# if !defined(XXH3_64bits) +# warning XXH3_64bits not defined +# endif +#endif + +#if !defined(XXH3_64bits) +# include "jhash.h" +#endif /* * Perl doesn't have a GC the same way (C) Ruby does, so no GC count. @@ -277,7 +293,16 @@ static const COP *mwp_curcop(void) static void hash_loc(struct src_loc *k, size_t len) { +#if defined(XXH3_64bits) + union { + XXH64_hash_t u64; + uint32_t u32[2]; + } u; + u.u64 = XXH3_64bits(k->k, len); + k->hval = u.u32[1]; +#else k->hval = jhash(k->k, len, 0xdeadbeef); +#endif } static struct src_loc *assign_line(size_t size, const char *file, unsigned line) |