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 19:08:12 +0530 Message-ID: References: <1b07c68a-873e-83c8-246d-423bc83a3881@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=001a114e7e8812b4d7054804fb34 X-Trace: blaine.gmane.org 1486561124 5576 195.159.176.226 (8 Feb 2017 13:38:44 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 8 Feb 2017 13:38:44 +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 14:38:40 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 1cbSSD-0001Dl-HZ for ged-emacs-devel@m.gmane.org; Wed, 08 Feb 2017 14:38:37 +0100 Original-Received: from localhost ([::1]:59531 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cbSSJ-0008J3-7q for ged-emacs-devel@m.gmane.org; Wed, 08 Feb 2017 08:38:43 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35770) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cbSSC-0008Is-LD for emacs-devel@gnu.org; Wed, 08 Feb 2017 08:38:37 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cbSSB-0006Om-JZ for emacs-devel@gnu.org; Wed, 08 Feb 2017 08:38:36 -0500 Original-Received: from mail-yw0-x244.google.com ([2607:f8b0:4002:c05::244]:35657) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cbSSB-0006Mj-Ev for emacs-devel@gnu.org; Wed, 08 Feb 2017 08:38:35 -0500 Original-Received: by mail-yw0-x244.google.com with SMTP id l16so11865215ywb.2 for ; Wed, 08 Feb 2017 05:38:33 -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; bh=MHzKNY8j6e5Fw5TQpQlJRCPrYZdJXSZlTo8XaEBrk6E=; b=Kx5YXLH0w/oJovUUfLypu6S6gRXJKA9Qgm0Y9Z4PMoRk7mb1E9UtwX5RDwA2cyRcnH Ym4QFDkcX4z7824VxxaPLONtghbRXui1b3QrM5hw1hFs/mpQNpmA4+InUu75O6kr5cel VyBQLkN5thM0Pcu5AtQP9INXRqvvgvf+O/86k948DPwptP/DZN7YFSf4g9nGz5iVA3NZ 1ySpFo/muIp7cNHm8rySCDVdot95yhVxuHet8CQYeo6eW7L4JNSg6h7GBPXpPtXCyR3Y UxFDVSwEBRxoQtImYqwc0u7gTeOfN02OfMLlL+v2LZ3TmBZvlppiWc0VaR5K7lTVEMri FISQ== 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; bh=MHzKNY8j6e5Fw5TQpQlJRCPrYZdJXSZlTo8XaEBrk6E=; b=VPb5asyaQJRMxXYMK/pe1qVUCnbc89jHt6S8strBFsXEgHCtBAoetBYIOwm2YB+jDt kEXmZbZBH5wxO2F2QdrheZb+WyZmGwYwYRCMdb1hPPCU+zP6UbijKj+W+e/Xzp4GYpk7 neG0EAIqiMaO6Vmsdz5OSRqyqdpHjbYKAnsFKCc16alleBpOQZ9fDOSN6y+/py5cclSz WoQIhR6WGQwYHnWmUp+KcSpYGkPLKa1pFSbtm8MAi+335MXxlXquGyRMmNRDc1dFhiCb UTnEP2QptAJGxZZX1ZXllx7jdIXhXu1iltt7a8JppqizqpVsjjwfkuhv+0s7uH3m0r5k y4zQ== X-Gm-Message-State: AMke39k5+O0Qf1ERROm/JXeLCC3sqgnV96Va4oxU4sitIPYRPS2gzqPkFDylpCWjMw+J6X33hdP252iAt/B2Ag== X-Received: by 10.13.208.132 with SMTP id s126mr14364231ywd.137.1486561112922; Wed, 08 Feb 2017 05:38:32 -0800 (PST) Original-Received: by 10.129.153.77 with HTTP; Wed, 8 Feb 2017 05:38:12 -0800 (PST) In-Reply-To: <1b07c68a-873e-83c8-246d-423bc83a3881@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4002:c05::244 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:212132 Archived-At: --001a114e7e8812b4d7054804fb34 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 be= about 5-7% slower. Hopefully linear-scan hash tables will make things muc= h faster :) The following patch makes hash_lookup use linear search when the number of = keys in the hash table is <=3D 5 (chosen arbitrarily). switch bytecode run with = this patch takes 15.96 seconds to run the benchmark, while the goto-if-nil code = takes 17.15 seconds. --=20 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) --001a114e7e8812b4d7054804fb34 Content-Type: text/plain; charset=US-ASCII; name="gethash-linear-search.diff" Content-Disposition: attachment; filename="gethash-linear-search.diff" Content-Transfer-Encoding: base64 X-Attachment-Id: f_iyx03gw42 ZGlmZiAtLWdpdCBhL3NyYy9mbnMuYyBiL3NyYy9mbnMuYwppbmRleCBhYzdjMWYyNjVhLi4yOTQw YmZkZmJiIDEwMDY0NAotLS0gYS9zcmMvZm5zLmMKKysrIGIvc3JjL2Zucy5jCkBAIC0zOTE1LDYg KzM5MTUsMTcgQEAgaGFzaF9sb29rdXAgKHN0cnVjdCBMaXNwX0hhc2hfVGFibGUgKmgsIExpc3Bf T2JqZWN0IGtleSwgRU1BQ1NfVUlOVCAqaGFzaCkKICAgcHRyZGlmZl90IHN0YXJ0X29mX2J1Y2tl dDsKICAgTGlzcF9PYmplY3QgaWR4OwogCisgIGlmIChIQVNIX1RBQkxFX1NJWkUgKGgpIDw9IDUg JiYgaC0+dGVzdC5jbXBmbikgeworICAgIC8qVHJ5IGRvaW5nIGEgbGluZWFyIHNlYXJjaCBmaXJz dCAqLworICAgIHB0cmRpZmZfdCBpOworICAgIGZvciAoaSA9IDA7IGkgPCBIQVNIX1RBQkxFX1NJ WkUgKGgpOyBpKyspCisgICAgICB7CisgICAgICAgIGlmIChoLT50ZXN0LmNtcGZuICgmaC0+dGVz dCwga2V5LCBIQVNIX0tFWSAoaCwgaSkpKQorICAgICAgICAgIHJldHVybiBpOworICAgICAgfQor ICAgIHJldHVybiAtMTsKKyAgfQorCiAgIGhhc2hfY29kZSA9IGgtPnRlc3QuaGFzaGZuICgmaC0+ dGVzdCwga2V5KTsKICAgZWFzc2VydCAoKGhhc2hfY29kZSAmIH5JTlRNQVNLKSA9PSAwKTsKICAg aWYgKGhhc2gpCg== --001a114e7e8812b4d7054804fb34--