mwrap (Perl version) user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: mwrap-perl@80x24.org
Subject: [PATCH] build: optionally support XXH3 from xxHash
Date: Sun, 20 Nov 2022 09:55:20 +0000	[thread overview]
Message-ID: <20221120095520.2424659-1-e@80x24.org> (raw)

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)

                 reply	other threads:[~2022-11-20  9:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221120095520.2424659-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=mwrap-perl@80x24.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).