From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Robert Boyer Newsgroups: gmane.emacs.devel Subject: Re: Some thoughts about Emacs performance Date: Fri, 16 Feb 2024 12:34:03 -0600 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000003e1773061183ff35" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18505"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Emacs developers , Gerard Huet To: Simon Leinen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Feb 16 20:36:55 2024 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 1rb410-0004cc-JJ for ged-emacs-devel@m.gmane-mx.org; Fri, 16 Feb 2024 20:36:54 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rb40F-0003vF-Bf; Fri, 16 Feb 2024 14:36:07 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rb32r-000420-5i for emacs-devel@gnu.org; Fri, 16 Feb 2024 13:34:45 -0500 Original-Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rb32o-0001RQ-Sk for emacs-devel@gnu.org; Fri, 16 Feb 2024 13:34:44 -0500 Original-Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-561587ce966so4619213a12.1 for ; Fri, 16 Feb 2024 10:34:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708108481; x=1708713281; darn=gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=FsmNRn7uPo5/iu4qcAZdpxpMKqCYi+AUxIQxTF1/3Hw=; b=JuT3OhmHiW2PpFHikTLF5MSyqWd44w3MAVaWtOKGMrNcQQu4bLkVEjBDCTkNXwwKUX ZQ0cM2EKOuSRAc8TDAUy3Aabp4H8iWYFAx9nIvmzmuS4nJSkYrVHIdiRJqbwD4mibwWG CbxSlZp6wukIqkYojCdo25suWwSUs6YSq4WvaZ9cYn/kTtvAxtjKjbHjCUYtoVr1Q0++ PavqWJQw/diSO/ZPoczpegwly+bSckcCxDGWGqX0Qi2DsjSiKqzd3HdiJkOduNLtkheA HhdLp0moJS9v024ht00EZpWY1s3BcvThuIKVlwYoPx+z5Jr0M3JYcVi0ZnSsG5THZD0o ld4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708108481; x=1708713281; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=FsmNRn7uPo5/iu4qcAZdpxpMKqCYi+AUxIQxTF1/3Hw=; b=DPZrVPLLj7RssOPA884f1y1KNrkHmDshUcQfKgw9rB5sR+RJix6ebeKQjJGEKqFAkH QOvmPQjJJGG4GIonFYNvoHMmaF9dq8dNYaPdRI7tmXbNxmBQPSg4HBj9YA0jjW/FxhfG j6pkEKZWiOzTNQ/zk5r8+aAAwaA15LNlHnvyF7ihHC7JcTl0RJLSp/c0bwScOonTK20N IFvZCMQVE1qs+MAzZbgyMeRfqO3/cVM32k5loZHoIia2N1fEaUCZwB6jYk4CBFyiP3Pq mPAGF58KqZULAwLzCzMWKGbRoPfdme4P54w2wFUdT8Q/K2Ga94grBvrQX36Mjye/JRtN dqDg== X-Gm-Message-State: AOJu0YzSPBALLZjJe+zZO8szF1ynYmnRDbzOf7WFmQc2Vq+h1bKd2fOv OK25lq1PeDP8g+jUAzbWNTrQJkwrIbxEQuTxl34iIb9ZOomBRweun8zF6ZbAYJ9Lf5Ddz0OE4lC 7RnDhgUsb00kZiRHAFcK6ZRKlorQ= X-Google-Smtp-Source: AGHT+IGDGbd5W3cylG3yklaolbNFVXIYKgp8/sTXk4mRfuQ6ae9T9aw5u5y2iU2i5FypgHpdmfRoEDx/ZeDKVPmWDSE= X-Received: by 2002:a50:ec85:0:b0:564:1735:19d0 with SMTP id e5-20020a50ec85000000b00564173519d0mr148581edr.1.1708108480909; Fri, 16 Feb 2024 10:34:40 -0800 (PST) In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::534; envelope-from=robertstephenboyer@gmail.com; helo=mail-ed1-x534.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, HTML_MESSAGE=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-Mailman-Approved-At: Fri, 16 Feb 2024 14:36:01 -0500 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-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:316253 Archived-At: --0000000000003e1773061183ff35 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable > > > But it doesn't try to be a standalone platform for > > performance-oriented Lisp developers. > > I hope that Emacs merges with SBCL. > > Emacs and SBCL are amongst the greatest inventions in the history of the > world. > > Of course I should mention gcc and Linux and so much that the Free > Software Foundation has given us, e.g., their 'sort' which can sort files > of amazing length at amazing speed. It is crucial to my ongoing work on > automatic theorem proving. If you've got a billion clause records and wa= nt > to flush duplicates, who you gonna call but /usr/bin/sort. That's what I > say, and what I do. To do that in Lisp might consume more space than I > have except on my SD card. I run on a $100 chromebook and my 256 gb SD > card only cost $30, and 1 tb SD cards are coming soon at a price I think = I > will be able to afford. > But of course, Coq may be the fastest thing except for C. And it has > 'sanitary' macros. > > Where would I be without unsanitary macros! My sorting algorithm 'msa' > depends upon them! > > But what do I know about sanitation. I think that the following are very unsanitary, but what do I know? (eval > '(defmacro key (x) > (cond (key > (cond ((symbolp key) `(the ,msa-type (,key ,x))) > (t `(the ,msa-type (funcall ,key ,x))))) > (t `(the ,msa-type ,x))))) > (eval > '(defmacro msa-equal (x y) > (cond (msa-all-keys-real `(eql ,x ,y)) > (t `(equal ,x ,y))))) > (eval > '(defmacro msa-predicate (x y) > (cond ((symbolp msa-predicate) `(,msa-predicate ,x ,y)) > (t `(funcall ',msa-predicate ,x ,y))))) On Fri, Feb 16, 2024 at 8:08=E2=80=AFAM Simon Leinen wrote: > Bob, > > welcome to the emacs-devel list, and thanks a lot for *your* wonderful > contributions (theorem prover, string search, and Lisp benchmarking - > I remember boyer.lisp from RPG's reference work[1]). > > On Thu, Feb 8, 2024 at 8:15=E2=80=AFAM Robert Boyer > wrote: > > > > Emacs 27.1 has a 'sort' function that takes longer than stable-sort of > SBCL. Maybe > > by a factor of 2. See also my attached file 'ms.lisp'. > > > > There may be a lot that can be improved in Emacs' > > handling of cl-loop, setf, elt, or cl-random. > > In this case, cl-random seems to be the main culprit for the slow > initialization=E2=80=94replacing that with plain "random" speeds it up by > about a factor of ten. There was some discussion on the list recently > about cl-random vs. random. The main functional difference is that > cl-random supports a defined state. But the performance difference may > be due more to the fact that random is written in C, and cl-random in > Lisp. > > As for the sorting itself, both Emacs and SBCL seem to use mergesort > in their implementations of (stable-)sort. Emacs's implementation is > written in C, SBCL's in Lisp. Performance is quite similar=E2=80=94on my > system (Apple Macbook Air M2) Emacs takes about 35% longer to sort a > million random numbers than SBCL. (On the other hand when sorting it > again, i.e. when the vector is already fully sorter, Emacs is quite a > bit faster than SBCL=E2=80=94maybe Emacs chose to optimize for partly-sor= ted > vectors at the expense of a bit of performance for random input.) > > In general, the Emacs Lisp runtime system and compiler(s) aren't as > optimized as SBCL for general Lisp use. But it gets quite close! > > On the other hand, Emacs has editor-specific code (e.g. redisplay) and > data structures (e.g. buffers) which are highly optimized and partly > written in C. But it doesn't try to be a standalone platform for > performance-oriented Lisp developers. Of course Emacs is very > suitable as a Software Development Environment for systems such as > SBCL, and there are many good integration options=E2=80=94personally I us= e the > SLIME package these days. > > Best regards, and enjoy Lisping in Emacs! > -- > Simon. > > > ;; First some Emacs, with times on my $100 Chromebook. > > > > (setq n 6) > > (defun make-random-array (n) > > (let ((a (make-vector n 0))) > > (cl-loop for i below n do > > (setf (elt a i) (cl-random 1000000))) > > a)) > > (byte-compile 'make-random-array) > > (benchmark '(setq foo (make-random-array (expt 10 n))) 1) -- 2.3 second= s > > (benchmark '(sort foo '<) 1) -- 1 second > > > > ;; Second some Common Lisp, with times for SBCL on my $100 Chromebook. > > > > (defparameter n 6) > > (defun make-random-array (n) > > (declare (fixnum n)) > > (let ((a (make-array n))) > > (declare (type array a)) > > (loop for i fixnum below n do > > (setf (aref a i) (random most-positive-fixnum))) > > a)) > > (time (defparameter foo (make-random-array (expt 10 n)))) -- .041 > seconds > > (time (progn (stable-sort foo '<) nil)) -- .45 seconds > > > > Thanks so much for Emacs, which is so great that I cannot put it > > into words. > > > > Bob > > > [1] https://dreamsongs.com/Files/Timrep.pdf > --0000000000003e1773061183ff35 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
> But it doesn't try to be a standalone platform fo= r
> performance-oriented Lisp developers.=C2=A0
=C2=A0
I hope that Emacs merges= with SBCL.=C2=A0=C2=A0
=C2=A0
Emacs and SBCL are amongst the greatest inventions in = the history of the world.
=C2=A0
Of course I should mention gcc and Linux and so much= that the Free Software Foundation has given us, e.g., their 'sort'= which can sort files of amazing length at amazing speed.=C2=A0 It is cruci= al to my ongoing work on automatic theorem proving.=C2=A0 If you've got= a billion clause records and want to flush duplicates, who you gonna call = but=C2=A0/usr/bin/sort.=C2=A0 That's what I say, and what I do.=C2=A0 T= o do that in Lisp might consume more space than I have except on my SD card= .=C2=A0 =C2=A0I run on a $100 chromebook and my 256 gb SD card only cost $3= 0, and 1 tb SD cards are coming soon at a price I think I will be able to a= fford.=C2=A0
=C2=A0=
But of course, Coq may be the fastest thing except for C.=C2=A0 And i= t has 'sanitary' macros.
=C2=A0
Wh= ere would I be without unsanitary macros!=C2=A0 My sorting algorithm 'm= sa' depends upon them!
=C2=A0
<= font face=3D"monospace">But what do I know about sanitation.

I think that the following are very unsanitary, bu= t what do I know?=C2=A0
=C2=A0=C2=A0 =C2= =A0 =C2=A0 =C2=A0 (eval
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0'= (defmacro key (x)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (cond (key=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(con= d ((symbolp key) `(the ,msa-type (,key ,x)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(t `(the ,ms= a-type (funcall ,key ,x)))))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 (t `(the ,msa-type ,x)))))
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 (eval
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0'(defmacro msa-equal (x = y)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (cond (msa-all-keys-real `(= eql ,x ,y))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 (t `(equal ,x ,y)))))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (eval
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0'(defmacro msa-predicate (x y)
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (cond ((symbolp msa-predicate) `(,msa-predi= cate ,x ,y))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 (t `(funcall ',msa-predicate ,x ,y)))))

On Fri, Feb 16, 2024 at 8:08=E2= =80=AFAM Simon Leinen <simon.l= einen@gmail.com> wrote:
Bob,

welcome to the emacs-devel list, and thanks a lot for *your* wonderful
contributions (theorem prover, string search, and Lisp benchmarking -
I remember boyer.lisp from RPG's reference work[1]).

On Thu, Feb 8, 2024 at 8:15=E2=80=AFAM Robert Boyer
<rober= tstephenboyer@gmail.com> wrote:
>
> Emacs 27.1 has a 'sort' function that takes longer than stable= -sort of SBCL. Maybe
> by a factor of 2. See also my attached file 'ms.lisp'.
>
> There may be a lot that can be improved in Emacs'
> handling of cl-loop, setf, elt, or cl-random.

In this case, cl-random seems to be the main culprit for the slow
initialization=E2=80=94replacing that with plain "random" speeds = it up by
about a factor of ten.=C2=A0 There was some discussion on the list recently=
about cl-random vs. random. The main functional difference is that
cl-random supports a defined state. But the performance difference may
be due more to the fact that random is written in C, and cl-random in
Lisp.

As for the sorting itself, both Emacs and SBCL seem to use mergesort
in their implementations of (stable-)sort.=C2=A0 Emacs's implementation= is
written in C, SBCL's in Lisp. Performance is quite similar=E2=80=94on m= y
system (Apple Macbook Air M2) Emacs takes about 35% longer to sort a
million random numbers than SBCL.=C2=A0 (On the other hand when sorting it<= br> again, i.e. when the vector is already fully sorter, Emacs is quite a
bit faster than SBCL=E2=80=94maybe Emacs chose to optimize for partly-sorte= d
vectors at the expense of a bit of performance for random input.)

In general, the Emacs Lisp runtime system and compiler(s) aren't as
optimized as SBCL for general Lisp use.=C2=A0 But it gets quite close!

On the other hand, Emacs has editor-specific code (e.g. redisplay) and
data structures (e.g. buffers) which are highly optimized and partly
written in C.=C2=A0 But it doesn't try to be a standalone platform for<= br> performance-oriented Lisp developers.=C2=A0 Of course Emacs is very
suitable as a Software Development Environment for systems such as
SBCL, and there are many good integration options=E2=80=94personally I use = the
SLIME package these days.

Best regards, and enjoy Lisping in Emacs!
--
Simon.

> ;; First some Emacs, with times on my $100 Chromebook.
>
> (setq n 6)
> (defun make-random-array (n)
>=C2=A0 =C2=A0(let ((a (make-vector n 0)))
>=C2=A0 =C2=A0 =C2=A0(cl-loop for i below n do
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (setf (elt a i) (cl-ra= ndom 1000000)))
>=C2=A0 =C2=A0 =C2=A0a))
> (byte-compile 'make-random-array)
> (benchmark '(setq foo (make-random-array (expt 10 n))) 1) -- 2.3 s= econds
> (benchmark '(sort foo '<) 1) -- 1 second
>
> ;; Second some Common Lisp, with times for SBCL on my $100 Chromebook.=
>
> (defparameter n 6)
> (defun make-random-array (n)
>=C2=A0 =C2=A0(declare (fixnum n))
>=C2=A0 =C2=A0(let ((a (make-array n)))
>=C2=A0 =C2=A0 =C2=A0(declare (type array a))
>=C2=A0 =C2=A0 =C2=A0(loop for i fixnum below n do
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(setf (aref a i) (random most-= positive-fixnum)))
>=C2=A0 =C2=A0 =C2=A0a))
> (time (defparameter foo (make-random-array (expt 10 n))))=C2=A0 -- .04= 1 seconds
> (time (progn (stable-sort foo '<) nil)) -- .45 seconds
>
> Thanks so much for Emacs, which is so great that I cannot put it
> into words.
>
> Bob


[1] https://dreamsongs.com/Files/Timrep.pdf

--0000000000003e1773061183ff35--