From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Vibhav Pant Newsgroups: gmane.emacs.devel Subject: Re: [PATCH]: Add new bytecode op `switch' for implementing branch tables. Date: Wed, 8 Feb 2017 21:51:23 +0530 Message-ID: References: <1b07c68a-873e-83c8-246d-423bc83a3881@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1486570912 5825 195.159.176.226 (8 Feb 2017 16:21:52 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 8 Feb 2017 16:21:52 +0000 (UTC) Cc: Stefan Monnier , "emacs-devel@gnu.org" To: =?UTF-8?Q?Cl=C3=A9ment_Pit=2DClaudel?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Feb 08 17:21:47 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cbV07-0001Cs-Hc for ged-emacs-devel@m.gmane.org; Wed, 08 Feb 2017 17:21:47 +0100 Original-Received: from localhost ([::1]:60286 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cbV0C-00052k-S4 for ged-emacs-devel@m.gmane.org; Wed, 08 Feb 2017 11:21:52 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55594) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cbV06-00050n-6t for emacs-devel@gnu.org; Wed, 08 Feb 2017 11:21:47 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cbV05-0001vZ-AR for emacs-devel@gnu.org; Wed, 08 Feb 2017 11:21:46 -0500 Original-Received: from mail-yw0-x242.google.com ([2607:f8b0:4002:c05::242]:34206) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cbV05-0001vR-5s for emacs-devel@gnu.org; Wed, 08 Feb 2017 11:21:45 -0500 Original-Received: by mail-yw0-x242.google.com with SMTP id v73so12257588ywg.1 for ; Wed, 08 Feb 2017 08:21:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=sux71vgEMV0TjbtINXoCP58SNsMctxpPwdjjJMWfO6w=; b=I1NX4qCH+JAXG7OOBxnGJCBuoeyBwPZkV2hfg3dL7tVFz4Se5gohUOWhFY7Y/DcvdP Ep+jUrcZKnqD1eD/nYqP+PjMlVm+Xkmc1uAM4qf2JAG+XwiMk+Vq7l04n2qpD+StzKXv M9Pt/1Knbu0EYkqpcUphpkzBtHdDATF4ukpaGljKTFkjChBxO1JtuXJOudOX66fqV3wm ThJdOjHUOWzHM9/8sEvEXRkSsHdj7YzxnEFphfiYBMTGOciKl69rr+hhdiGpnjdfjEUN OEDn/nhLuc2drJweRQ4QpAyhTraNmifRCKduumDgC8IKKd601Z9W0X6vZXblhdaSiRsq D9vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=sux71vgEMV0TjbtINXoCP58SNsMctxpPwdjjJMWfO6w=; b=H1dOpE1Qv3UFQhWBl2njvXcJMnZhvbfWDr9SP3QC45b5pYPsUwaygQV711nP3O2bCg Vu/B4Qib5RbaHfSbZ3O/IUqHWKSmzA1t7rfrWoBHWdqrHCTpzJnklJtBr4hY0SwAWAEh 1vRqOAMVGKtHeJyyArfWinc9C+BmQMFjAPDb+q2FTCULce/C1ZryKwXp76uy/1YEky5U 3yrMZJVPlNgEGVsE9BzprtBcDH+HyLp+1XociX6EaLPS7vEB34nuucph1rCtIcqaCEEN NLrKE75hmtWHTqV3Je9AI0+FLWcthh0aJUHKjk2rpGOh7lNCaDRCKsZ5UCY9VazZji2W 5Pcg== X-Gm-Message-State: AIkVDXIglSAspVzN06GhQ+ujfuki37ThadpwDjHGS3i8l01OfWRsmseSHiiWg17e8nLw4v/tyY4IMThy+FFY8g== X-Received: by 10.129.71.11 with SMTP id u11mr14970275ywa.79.1486570904300; Wed, 08 Feb 2017 08:21:44 -0800 (PST) Original-Received: by 10.129.153.77 with HTTP; Wed, 8 Feb 2017 08:21:23 -0800 (PST) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4002:c05::242 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:212135 Archived-At: On Wed, Feb 8, 2017 at 7:08 PM, Vibhav Pant wrote: > On Tue, Feb 7, 2017 at 9:26 PM, Cl=C3=A9ment Pit-Claudel > wrote: >> The timings fluctuate quite a bit, but the byte-switch branch seems to b= e about 5-7% slower. Hopefully linear-scan hash tables will make things mu= ch faster :) > > The following patch makes hash_lookup use linear search when the number o= f keys > in the hash table is <=3D 5 (chosen arbitrarily). switch bytecode run wit= h this > patch takes 15.96 seconds to run the benchmark, while the goto-if-nil cod= e takes > 17.15 seconds. > > -- > Vibhav Pant > vibhavp@gmail.com > > diff --git a/src/fns.c b/src/fns.c > index ac7c1f265a..2940bfdfbb 100644 > --- a/src/fns.c > +++ b/src/fns.c > @@ -3915,6 +3915,17 @@ hash_lookup (struct Lisp_Hash_Table *h, > Lisp_Object key, EMACS_UINT *hash) > ptrdiff_t start_of_bucket; > Lisp_Object idx; > > + if (HASH_TABLE_SIZE (h) <=3D 5 && h->test.cmpfn) { > + /*Try doing a linear search first */ > + ptrdiff_t i; > + for (i =3D 0; i < HASH_TABLE_SIZE (h); i++) > + { > + if (h->test.cmpfn (&h->test, key, HASH_KEY (h, i))) > + return i; > + } > + return -1; > + } > + > hash_code =3D h->test.hashfn (&h->test, key); > eassert ((hash_code & ~INTMASK) =3D=3D 0); > if (hash) Looks like this is the incorrect way to linear-search a hash table, as it's sometimes resulting in duplicate hash table entries. --=20 Vibhav Pant vibhavp@gmail.com