From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Simon Leinen Newsgroups: gmane.emacs.devel Subject: Re: Some thoughts about Emacs performance Date: Fri, 16 Feb 2024 15:08:28 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22755"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Emacs developers To: Robert Boyer Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Feb 16 15:09:47 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 1rayuQ-0005fr-V0 for ged-emacs-devel@m.gmane-mx.org; Fri, 16 Feb 2024 15:09:46 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1raytS-0003n2-75; Fri, 16 Feb 2024 09:08:46 -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 1raytP-0003mr-TU for emacs-devel@gnu.org; Fri, 16 Feb 2024 09:08:43 -0500 Original-Received: from mail-il1-x12d.google.com ([2607:f8b0:4864:20::12d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1raytO-0005hx-2F for emacs-devel@gnu.org; Fri, 16 Feb 2024 09:08:43 -0500 Original-Received: by mail-il1-x12d.google.com with SMTP id e9e14a558f8ab-364f794f237so7053175ab.1 for ; Fri, 16 Feb 2024 06:08:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708092520; x=1708697320; darn=gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=1iTBuqz10HzXY1XBRAI+rS/fagmu3kYjPrR1+/I3+WU=; b=Ba/aVRXc5Aqm/Gti8p9IZFTf8RNparIOCoCRyByF3liB0QGW0F/Y5n028I+o2vtzbU SaBB8Py2C71KrstZfJz2z0UDOvr2stFl5lb0E6BMdjqXts2rry5jj1xw8mZccJzXL8Ov d7NZx6LLwDk7TOolg6v5tdznTxrUOG00GtomhPvAgrolmh6djMFfa1QzDvt4SZgAN+Ig MBLnn2Go3vIB7hHgnyAiKbHBiekOJRaLrvAjFNv/+TNiCHNUBEpFGkPU0lmEwveO+ltF +qOgIyDbDLTIUwr+pRQ46i+FElj2Yfyil2EHFERJruXmurMcTHqrtLUJ4hV7DHL5GA9i +xIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708092520; x=1708697320; h=content-transfer-encoding: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=1iTBuqz10HzXY1XBRAI+rS/fagmu3kYjPrR1+/I3+WU=; b=KA3AThJEVCNrcNwwCOLYCkQdGWuaazovk6pObVvaK63vYX2bkEfI49hKbsj9DmW/CC IJX0U0LhPLdLVgCPAIDaRuuCpNYjgvN2xm6+lJTotozEoC+b+qDSQbs6PZ7GulAsc4oG 4+G07vYNe6XJFHHCXrT9ooNBpasN8fz3Cl7VeXH091my9aT30TRUiObvEcT+DsIXN4M6 wR06SibOGO9HoyDM6opZPMzni/P/iX07zLQGdxgb1YFQVMzLHjFSaMpxtsDUlRkJm8ii JFnLEtMkoGKRy9yUEJa48VIQHaYnfM5gYhWhavrLTN/YJUcZRWWbqsT0aZ7hdyeEqsUC CkfA== X-Gm-Message-State: AOJu0YyLABIJGSPmVByKZZsO4qfdZ6N9rY4v0Bkr0utSg/hy8/aYY9qV Zcsq/7tST9eNrn38WoOVostXlSmK8zfPq8IhHgImiB8koVgu3JEUKcz6zkU3Au/CYAnTFsg9DFM VO6lmoEYEwaK4yAMuggfR1YL/jz0= X-Google-Smtp-Source: AGHT+IEuXpVPhZHPExTCwwYUky27rjKlI9Zp64ich+KUoJKcx10hKblmGZYL4V11jiEqJf8XgkESmQqvFzjX9pPcNnI= X-Received: by 2002:a05:6e02:f46:b0:363:dfc7:acc1 with SMTP id y6-20020a056e020f4600b00363dfc7acc1mr1669993ilj.2.1708092520079; Fri, 16 Feb 2024 06:08:40 -0800 (PST) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::12d; envelope-from=simon.leinen@gmail.com; helo=mail-il1-x12d.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-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:316249 Archived-At: 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 SB= CL. 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-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. 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 use = the SLIME package these days. Best regards, and enjoy Lisping in Emacs! --=20 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 seconds > (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 second= s > (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