From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Redisplay slower in Emacs 28 than Emacs 27 Date: Tue, 08 Dec 2020 17:46:51 -0500 Message-ID: References: <878sa9hbe2.fsf@gnus.org> <877dptfvae.fsf@gnus.org> <83czzl8qwu.fsf@gnu.org> <87sg8h78s8.fsf@gnus.org> <837dpt8lk5.fsf@gnu.org> <87pn3kjssr.fsf@gnus.org> <83im9c70vu.fsf@gnu.org> <87im9cfeej.fsf@gnus.org> <837dps6xyv.fsf@gnu.org> <87czzkdx57.fsf@gnus.org> <83v9dc5he3.fsf@gnu.org> <87r1o0chk9.fsf@gnus.org> <83tusw5g5o.fsf@gnu.org> <87360gaz7o.fsf@gnus.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13919"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: ghe@sdf.org, Eli Zaretskii , emacs-devel@gnu.org To: Lars Ingebrigtsen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Dec 09 00:10:57 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kmm8H-0003Xj-Ak for ged-emacs-devel@m.gmane-mx.org; Wed, 09 Dec 2020 00:10:57 +0100 Original-Received: from localhost ([::1]:33910 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kmm8G-0005pG-7y for ged-emacs-devel@m.gmane-mx.org; Tue, 08 Dec 2020 18:10:56 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36984) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmll4-0005C0-PP for emacs-devel@gnu.org; Tue, 08 Dec 2020 17:47:00 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:44996) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmll2-0000uX-9S; Tue, 08 Dec 2020 17:46:57 -0500 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 62C63810A3; Tue, 8 Dec 2020 17:46:54 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id CEB6D80B07; Tue, 8 Dec 2020 17:46:52 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1607467612; bh=YrZk17zSbWcJw/WX0v5U9w6M8O1i3uLnJQXmaiBkn5o=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=I4JDQz+rnbWNT5agAphoITL98RdnC3ZabzP7yvqiCOHVNLzppi6vQFGHNKijVuLDt mPnKxDyHUq7d6BjJYj0Np4PZYkhpfk9bzp25LFg/6FCy10SzxiubGmlF+P01cNkv6y iM+F0N+/6p5cpxs4sQiQ5wtLVJEb48tdNTTEbJH7Or/v4Xf/zUN6pc826GxUlPsNkc QIpHo0bSZSqvjgph1dd9cnFkVPLWLLPPp7MsHc+esieXNCOycNlGqEnUYF2sHxyoGz Qde5YNSvSrv74nQyLuc6DZSVvu4EmuQ9DHU33IvKn80N9E+Y3F6on9kIlzktXs/Ef1 bnsHSTPMn0GKQ== Original-Received: from alfajor (69-165-136-52.dsl.teksavvy.com [69.165.136.52]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 7F3D4120205; Tue, 8 Dec 2020 17:46:52 -0500 (EST) In-Reply-To: (Stefan Monnier's message of "Tue, 08 Dec 2020 16:33:45 -0500") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:260592 Archived-At: >> :data image, current sxhash, Fequal: 6.4s. >> :data image, NOOP sxhash, Fequal: 3.4s. > > Maybe it's time we speed up `hash_string`. > There's a lot of room for improvement there, AFAICT, e.g.: > - work on `EMACS_UINT` chunks instead of `char` chunks. > - Bound the amount of work (e.g. do a max of, say, 10 chunks, equally > spaced throughout the string). E.g. Stefan diff --git a/src/fns.c b/src/fns.c index e4c9acc316..23d24ef4db 100644 --- a/src/fns.c +++ b/src/fns.c @@ -4525,18 +4526,40 @@ #define SXHASH_MAX_LEN 7 EMACS_UINT hash_string (char const *ptr, ptrdiff_t len) { - char const *p = ptr; - char const *end = p + len; - unsigned char c; - EMACS_UINT hash = 0; - - while (p != end) + if (len < 16) { - c = *p++; - hash = sxhash_combine (hash, c); + char const *p = ptr; + char const *end = p + len; + EMACS_UINT hash = len; + + while (p < end) + { + unsigned char c = *p++; + hash = sxhash_combine (hash, c); + } + + return hash; } + else + { + EMACS_UINT const *p = (EMACS_UINT const *) ptr; + EMACS_UINT const *end = (EMACS_UINT const *) (ptr + len); + EMACS_UINT hash = len; + /* At most 8 steps. We could reuse SXHASH_MAX_LEN, of course, + * but dividing by 8 is cheaper. */ + ptrdiff_t step = max (1, (end - p) >> 3); + + /* Beware: `end` might be unaligned, so `p < end` is not always the same + * as `p <= end - 1`. */ + while (p <= end - 1) + { + EMACS_UINT c = *p; + p += step; + hash = sxhash_combine (hash, c); + } - return hash; + return hash; + } } /* Return a hash for string PTR which has length LEN. The hash