From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Robert Pluim Newsgroups: gmane.emacs.devel Subject: Lisp interpreter micro-optimization Date: Tue, 26 Jul 2022 14:36:33 +0200 Message-ID: <877d4082zy.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2487"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Jul 26 14:43:49 2022 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 1oGJue-0000WX-K2 for ged-emacs-devel@m.gmane-mx.org; Tue, 26 Jul 2022 14:43:48 +0200 Original-Received: from localhost ([::1]:47604 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oGJud-00021J-NT for ged-emacs-devel@m.gmane-mx.org; Tue, 26 Jul 2022 08:43:47 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37106) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGJnj-00030x-DV for emacs-devel@gnu.org; Tue, 26 Jul 2022 08:36:39 -0400 Original-Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]:44705) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oGJnh-0002Bj-Mc for emacs-devel@gnu.org; Tue, 26 Jul 2022 08:36:39 -0400 Original-Received: by mail-wr1-x436.google.com with SMTP id l15so15903723wro.11 for ; Tue, 26 Jul 2022 05:36:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:message-id:date:gmane-reply-to-list:subject:to:from :from:to:cc; bh=QbGaayotIIAnuR6m4ALQjfwVindVUEn+ObTxj1XXiio=; b=JeTvEszfWClNwmL12nBzPrgOqepCW4Ub9IUJDUv51tsiI/gHpj8o5OL8AnMXuDEI0F ubXTQu+eObqPvlDYMmKcFnuKqXXFBmEu7pxzgwd6JgsCjd0J39w8SrhX2r2rd+nepr9O hrO0qRKqw5s8ldh5HTMMv7LKgx1pvKITPo+dQj29fILjes1ovqRXtH2xQ1Jfqpd1Zziw aG6bsesUe+lQwJtKa8IIf4opL79o0KWU4iTdWed15MKvS+YI6vLDMMqRbZXoY6ufUvGI 7jZtAFy42swqh7dxyBme97VEd9Vrz9LgcJWsBN0ZihIoQfysEkTjcotW8Ylx6U0WGvuu +y4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:gmane-reply-to-list:subject:to:from :x-gm-message-state:from:to:cc; bh=QbGaayotIIAnuR6m4ALQjfwVindVUEn+ObTxj1XXiio=; b=EhF26/Hgdy2WFPGOCBctFv/bw4W8gBDsiscC5xQa4MvrZO9oavxEG7IBuMIHV9+yo5 noU24GH4GBlxb72ej89sNSGpCBeqcYDx1ZBbaL+q1QLE9K5wO4qqxAc0H4cdv3olpLJA 5VFvpnUxLktrUe8AHj2rHcjE9wqCtTq1qA/SzLIX5hq5+9PYSS5jWa2YqX2ZRm2RXQJ4 rQpSm5rpDprIOFbcbQjdzvKUsi4xoc/HyZ3ExKnC4ClJlKtcqEj35myo6ZGhifwK8FTZ CATVzhcAbyzBME2UxiHGBZZPiP+ny1XVtYJxiCeDSdHLTYD2XPFg/NlfxT5PuGP8sC5S sC7w== X-Gm-Message-State: AJIora8ntsZvleSZ9leBE2Ms1YR3hzV29a9aKbvkXHJqMM2XAgvxNezv oqkb4qqFe3cwaGWnlbbiVHGsgy2bFKk= X-Google-Smtp-Source: AGRyM1tpaZv+SLlzg65xqoi7wuKdGcenB17Bi097bfBTRQfTf/lLMgDZykB2sAHr0GT2nJGMs57b/Q== X-Received: by 2002:a5d:64aa:0:b0:21e:be27:6dfb with SMTP id m10-20020a5d64aa000000b0021ebe276dfbmr12390wrp.456.1658838995635; Tue, 26 Jul 2022 05:36:35 -0700 (PDT) Original-Received: from rltb ([2a01:e0a:3f3:fb50:7834:6702:759c:618d]) by smtp.gmail.com with ESMTPSA id o27-20020a5d58db000000b0021d80f53324sm14212266wrf.7.2022.07.26.05.36.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 05:36:34 -0700 (PDT) Gmane-Reply-To-List: yes Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=rpluim@gmail.com; helo=mail-wr1-x436.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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:292682 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi, I noticed we have an assq_no_quit, but no memq_no_quit, so came up with the attached, which I=CA=BCm convinced speeds up elisp by at least .01% (I=CA=BCm using Larsi-maths =F0=9F=98=BA), but I=CA=BCm not convinced = it=CA=BCs worth pushing. Robert --=20 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Add-memq_no_quit.patch >From 6be3aedccd26fd20040be999a62874188f93469e Mon Sep 17 00:00:00 2001 From: Robert Pluim Date: Tue, 26 Jul 2022 14:24:42 +0200 Subject: [PATCH] Add memq_no_quit To: emacs-devel@gnu.org We have an assq_no_quit, but no memq_no_quit. Add it and use it when accessing Vinternal_interpreter_environment, which is always safe. * src/fns.c (memq_no_quit): New function, no_quit version of 'memq'. * src/lisp.h: Add 'memq_no_quit' prototype. * src/eval.c (Fsetq): Use 'assq_no_quit'. (FletX, Flet): Use 'memq_no_quit'. (eval_sub): Use 'assq_no_quit'. --- src/eval.c | 8 ++++---- src/fns.c | 12 ++++++++++++ src/lisp.h | 1 + 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/eval.c b/src/eval.c index 141d2546f0..0477346d42 100644 --- a/src/eval.c +++ b/src/eval.c @@ -501,7 +501,7 @@ DEFUN ("setq", Fsetq, Ssetq, 0, UNEVALLED, 0, Lisp_Object lex_binding = ((!NILP (Vinternal_interpreter_environment) /* Mere optimization! */ && SYMBOLP (sym)) - ? Fassq (sym, Vinternal_interpreter_environment) + ? assq_no_quit (sym, Vinternal_interpreter_environment) : Qnil); if (!NILP (lex_binding)) XSETCDR (lex_binding, val); /* SYM is lexically bound. */ @@ -947,7 +947,7 @@ DEFUN ("let*", FletX, SletX, 1, UNEVALLED, 0, if (!NILP (lexenv) && SYMBOLP (var) && !XSYMBOL (var)->u.s.declared_special - && NILP (Fmemq (var, Vinternal_interpreter_environment))) + && NILP (memq_no_quit (var, Vinternal_interpreter_environment))) /* Lexically bind VAR by adding it to the interpreter's binding alist. */ { @@ -1022,7 +1022,7 @@ DEFUN ("let", Flet, Slet, 1, UNEVALLED, 0, if (!NILP (lexenv) && SYMBOLP (var) && !XSYMBOL (var)->u.s.declared_special - && NILP (Fmemq (var, Vinternal_interpreter_environment))) + && NILP (memq_no_quit (var, Vinternal_interpreter_environment))) /* Lexically bind VAR by adding it to the lexenv alist. */ lexenv = Fcons (Fcons (var, tem), lexenv); else @@ -2354,7 +2354,7 @@ eval_sub (Lisp_Object form) already did that when let-binding the variable. */ Lisp_Object lex_binding = (!NILP (Vinternal_interpreter_environment) /* Mere optimization! */ - ? Fassq (form, Vinternal_interpreter_environment) + ? assq_no_quit (form, Vinternal_interpreter_environment) : Qnil); return !NILP (lex_binding) ? XCDR (lex_binding) : Fsymbol_value (form); } diff --git a/src/fns.c b/src/fns.c index 7e78bba3a0..fe3a01c2de 100644 --- a/src/fns.c +++ b/src/fns.c @@ -1785,6 +1785,18 @@ DEFUN ("memq", Fmemq, Smemq, 2, 2, 0, return Qnil; } +/* Like Fmemq but never report an error and do not allow quits. + Use only on objects known to be non-circular lists. */ + +Lisp_Object +memq_no_quit (Lisp_Object elt, Lisp_Object list) +{ + for (; ! NILP (list); list = XCDR (list)) + if (EQ (XCAR (list), elt)) + return list; + return Qnil; +} + DEFUN ("memql", Fmemql, Smemql, 2, 2, 0, doc: /* Return non-nil if ELT is an element of LIST. Comparison done with `eql'. The value is actually the tail of LIST whose car is ELT. */) diff --git a/src/lisp.h b/src/lisp.h index 8fcc9b6e75..e92540c258 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4033,6 +4033,7 @@ #define CONS_TO_INTEGER(cons, type, var) \ extern Lisp_Object nconc2 (Lisp_Object, Lisp_Object); extern Lisp_Object assq_no_quit (Lisp_Object, Lisp_Object); extern Lisp_Object assoc_no_quit (Lisp_Object, Lisp_Object); +extern Lisp_Object memq_no_quit (Lisp_Object, Lisp_Object); extern void clear_string_char_byte_cache (void); extern ptrdiff_t string_char_to_byte (Lisp_Object, ptrdiff_t); extern ptrdiff_t string_byte_to_char (Lisp_Object, ptrdiff_t); -- 2.37.1.116.g9dd64cb4d3 --=-=-=--