From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.bugs Subject: bug#42998: 27.1; gnutls-symmetric-encrypt slow when providing cipher as symbol Date: Mon, 24 Aug 2020 15:01:01 +0200 Message-ID: <87y2m4ci5u.fsf@gnus.org> References: <20200823164330.GA72308@odonien.localdomain> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17642"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 42998@debbugs.gnu.org To: Vasilij Schneidermann Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Aug 24 15:03:02 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1kAC7n-0004Nw-IC for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 24 Aug 2020 15:02:59 +0200 Original-Received: from localhost ([::1]:49134 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kAC7m-0004AC-Fb for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 24 Aug 2020 09:02:58 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45174) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kAC6s-0003Sh-G7 for bug-gnu-emacs@gnu.org; Mon, 24 Aug 2020 09:02:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:44946) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kAC6s-0006zB-43 for bug-gnu-emacs@gnu.org; Mon, 24 Aug 2020 09:02:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kAC6s-0006qu-0R for bug-gnu-emacs@gnu.org; Mon, 24 Aug 2020 09:02:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Lars Ingebrigtsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 24 Aug 2020 13:02:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 42998 X-GNU-PR-Package: emacs Original-Received: via spool by 42998-submit@debbugs.gnu.org id=B42998.159827407526283 (code B ref 42998); Mon, 24 Aug 2020 13:02:01 +0000 Original-Received: (at 42998) by debbugs.gnu.org; 24 Aug 2020 13:01:15 +0000 Original-Received: from localhost ([127.0.0.1]:56492 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kAC67-0006pr-H7 for submit@debbugs.gnu.org; Mon, 24 Aug 2020 09:01:15 -0400 Original-Received: from quimby.gnus.org ([95.216.78.240]:56786) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kAC64-0006pb-F1 for 42998@debbugs.gnu.org; Mon, 24 Aug 2020 09:01:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=hvDfxhr5rQfxhD4NqIxW/Og/wEE/bFnRqlTfkKbZE7M=; b=BCiIKUx4dxdiSjjWbK+Z2yWZQE UnBiaWw0PFkUy06r+ywvNeONHARtJ2cCTrpt/+TdticiO1HBBrnm4fFiakwL/iUFo2hWC6DOceWog IFssbcD2XIkh+8Ht2xy3TghupXAjwnol5FwK5pjHUgIER2rYqKbV8mpoTokQdrtexTVc=; Original-Received: from cm-84.212.202.86.getinternet.no ([84.212.202.86] helo=xo) by quimby with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kAC5u-0006Jb-SA; Mon, 24 Aug 2020 15:01:05 +0200 X-Now-Playing: Kokoko!'s _Fongola_: "Kitoko" In-Reply-To: <20200823164330.GA72308@odonien.localdomain> (Vasilij Schneidermann's message of "Sun, 23 Aug 2020 18:43:30 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:186131 Archived-At: Vasilij Schneidermann writes: > I'd consider either to > document this behavior or making the mapping more efficient, for example > by caching the cipher list instead of recomputing it over and over > again. The following fixes the problem, but I'm not quite sure whether it's correct... Is initialising a Lisp_Object to NULL something that's allowed over all platforms? I can't initialise it to the more natural Qnil, since that's not a constant, C-wise. diff --git a/src/gnutls.c b/src/gnutls.c index 416fb15470..75bc7d970f 100644 --- a/src/gnutls.c +++ b/src/gnutls.c @@ -2303,6 +2303,8 @@ gnutls_symmetric (bool encrypting, Lisp_Object cipher, Lisp_Object key, Lisp_Object iv, Lisp_Object input, Lisp_Object aead_auth) { + static Lisp_Object cipher_cache = NULL; + if (BUFFERP (key) || STRINGP (key)) key = list1 (key); @@ -2329,7 +2331,12 @@ gnutls_symmetric (bool encrypting, Lisp_Object cipher, if (SYMBOLP (cipher)) { - info = Fassq (cipher, Fgnutls_ciphers ()); + if (! cipher_cache) + { + cipher_cache = Fgnutls_ciphers (); + staticpro (&cipher_cache); + } + info = Fassq (cipher, cipher_cache); if (!CONSP (info)) xsignal2 (Qerror, build_string ("GnuTLS cipher is invalid or not found"), -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no