* [PATCH] build: optionally support XXH3 from xxHash
@ 2022-11-20 9:55 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2022-11-20 9:55 UTC (permalink / raw)
To: mwrap-perl
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.
---
Makefile.PL | 12 ++++++++++++
mwrap_core.h | 27 ++++++++++++++++++++++++++-
2 files changed, 38 insertions(+), 1 deletion(-)
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)
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2022-11-20 9:55 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-20 9:55 [PATCH] build: optionally support XXH3 from xxHash Eric Wong
Code repositories for project(s) associated with this public inbox
https://80x24.org/mwrap-perl.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).