From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ihor Radchenko Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Re: Bignum performance (was: Shrinking the C core) Date: Fri, 11 Aug 2023 19:41:22 +0000 Message-ID: <87il9l1i59.fsf@localhost> References: <20230809094655.793FC18A4654@snark.thyrsus.com> <87il9owg0f.fsf@yahoo.com> <83fs4rjq9j.fsf@gnu.org> <87jzu2tvfc.fsf@dataswamp.org> <87y1ih3mc1.fsf@localhost> <87h6p5kcek.fsf@dataswamp.org> <87msyxoj2t.fsf@localhost> <875y5lkb4b.fsf@dataswamp.org> <87bkfdsmde.fsf@localhost> <87v8dlihc5.fsf@dataswamp.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="18725"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Emanuel Berg Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Aug 11 21:41:37 2023 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 1qUY0v-0004hl-4K for ged-emacs-devel@m.gmane-mx.org; Fri, 11 Aug 2023 21:41:37 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qUY0W-0006qf-ER; Fri, 11 Aug 2023 15:41:12 -0400 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 1qUY0S-0006q2-Ry for emacs-devel@gnu.org; Fri, 11 Aug 2023 15:41:09 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qUY0N-0001SK-Mj for emacs-devel@gnu.org; Fri, 11 Aug 2023 15:41:08 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 34427240104 for ; Fri, 11 Aug 2023 21:41:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1691782861; bh=3VIEIA/CdStHxw362ChDnG/M2tl9wf5K4DVR2gDHTvg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:From; b=QzxombTR+9Ye15EswBKig73HRyoiFhnq9l7Ev+rG4FW6MUusfuoXFiiY7KyvO6F04 1w2E/IzvwTSBOreEASZZsUxpFWd0ip4N9CUDXnnCjuuzmr5P8Hxb/noQ/qzBdF49hz lnGLGqa8nJX6cjoV0fKUbKV43sjtXbZ/9JUwWkAxidnTUn8Mig+5wWAsRQ6FZftDmR dWxtW9jkV3zliJuoBoPuUb2+ePqz0YwmB+FAn79ddeezjYmexe5YliPbiDmpD3zFV6 eKCAWYulU/wdgBLo4ZgZJX+hLRuMIfC6zfDnRI8hF4XPtW71hvOZhRTIucuwKpkvE3 A1zrhoEOYxvUg== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4RMvKm4yMLz9rxM; Fri, 11 Aug 2023 21:40:59 +0200 (CEST) In-Reply-To: <87v8dlihc5.fsf@dataswamp.org> Received-SPF: pass client-ip=185.67.36.66; envelope-from=yantar92@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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.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:308592 Archived-At: Emanuel Berg writes: >> And... is has been already done, actually. >> allocate_vectorlike calls allocate_vector_from_block, which >> re-uses pre-allocated objects. >> >> And looking into the call graph, this exact branch calling >> allocate_vector_from_block is indeed called for the bignums [...] > > Are we talking a list of Emacs C functions executing with the > corresponding times they have been in execution in a tree data > structure? :O That's what GNU perf does - it is a sampling profiler in GNU/Linux. The Elisp equivalent is profiler.el, but it does not reveal underlying C functions. > E.g. where do we find allocate_vectorlike ? I have listed the commands I used (from terminal): 1. perf record ~/Git/emacs/src/emacs -Q -batch -l /tmp/fib.eln 2. perf report You need Emacs compiled with debug symbols the get meaningful output. See more at https://www.brendangregg.com/perf.html > See if you can do my original test, which was 1-3 Elisp, > byte-compiled Elisp, and natively compiled Elisp, and the > Common Lisp execution (on your computer), if you'd like. As you wish: $ ~/Git/emacs/src/emacs -Q -batch -l /tmp/fib.el [5.783 s] $ ~/Git/emacs/src/emacs -Q -batch -l /tmp/fib.elc [1.961 s] $ ~/Git/emacs/src/emacs -Q -batch -l /tmp/fib.eln [1.901 s] $ SBCL_HOME=/usr/lib64/sbcl sbcl --load /tmp/fib.cl [0.007 s] without the patch (on my system) $ ~/Git/emacs/src/emacs -Q -batch -l /tmp/fib.el [6.546 s] $ ~/Git/emacs/src/emacs -Q -batch -l /tmp/fib.elc [2.498 s] $ ~/Git/emacs/src/emacs -Q -batch -l /tmp/fib.eln [2.518 s] Also, the patch gives improvements for more than just bignums. I ran elisp-benchmarks (https://elpa.gnu.org/packages/elisp-benchmarks.html) and got (before the patch) | test | non-gc avg (s) | gc avg (s) | gcs avg | tot avg (s) | tot avg err (s) | |--------------------+----------------+------------+---------+-------------+-----------------| | bubble | 0.70 | 0.06 | 1 | 0.76 | 0.07 | | bubble-no-cons | 1.17 | 0.00 | 0 | 1.17 | 0.02 | | bytecomp | 1.74 | 0.29 | 13 | 2.03 | 0.12 | | dhrystone | 2.30 | 0.00 | 0 | 2.30 | 0.07 | | eieio | 1.25 | 0.13 | 7 | 1.38 | 0.03 | | fibn | 0.00 | 0.00 | 0 | 0.00 | 0.00 | | fibn-named-let | 1.53 | 0.00 | 0 | 1.53 | 0.03 | | fibn-rec | 0.00 | 0.00 | 0 | 0.00 | 0.00 | | fibn-tc | 0.00 | 0.00 | 0 | 0.00 | 0.00 | | flet | 1.48 | 0.00 | 0 | 1.48 | 0.04 | | inclist | 1.07 | 0.00 | 0 | 1.07 | 0.02 | | inclist-type-hints | 1.00 | 0.00 | 0 | 1.00 | 0.07 | | listlen-tc | 0.13 | 0.00 | 0 | 0.13 | 0.03 | | map-closure | 5.26 | 0.00 | 0 | 5.26 | 0.09 | | nbody | 1.61 | 0.17 | 1 | 1.78 | 0.06 | | pack-unpack | 0.31 | 0.02 | 1 | 0.33 | 0.00 | | pack-unpack-old | 0.50 | 0.05 | 3 | 0.55 | 0.02 | | pcase | 1.85 | 0.00 | 0 | 1.85 | 0.05 | | pidigits | 4.41 | 0.96 | 17 | 5.37 | 0.13 | | scroll | 0.64 | 0.00 | 0 | 0.64 | 0.01 | | smie | 1.59 | 0.04 | 2 | 1.63 | 0.03 | |--------------------+----------------+------------+---------+-------------+-----------------| | total | 28.54 | 1.72 | 45 | 30.26 | 0.26 | (after the patch) | test | non-gc avg (s) | gc avg (s) | gcs avg | tot avg (s) | tot avg err (s) | |--------------------+----------------+------------+---------+-------------+-----------------| | bubble | 0.68 | 0.05 | 1 | 0.73 | 0.04 | | bubble-no-cons | 1.00 | 0.00 | 0 | 1.00 | 0.04 | | bytecomp | 1.60 | 0.23 | 13 | 1.82 | 0.16 | | dhrystone | 2.03 | 0.00 | 0 | 2.03 | 0.05 | | eieio | 1.08 | 0.12 | 7 | 1.20 | 0.07 | | fibn | 0.00 | 0.00 | 0 | 0.00 | 0.00 | | fibn-named-let | 1.44 | 0.00 | 0 | 1.44 | 0.12 | | fibn-rec | 0.00 | 0.00 | 0 | 0.00 | 0.00 | | fibn-tc | 0.00 | 0.00 | 0 | 0.00 | 0.00 | | flet | 1.36 | 0.00 | 0 | 1.36 | 0.09 | | inclist | 1.00 | 0.00 | 0 | 1.00 | 0.00 | | inclist-type-hints | 1.00 | 0.00 | 0 | 1.00 | 0.07 | | listlen-tc | 0.11 | 0.00 | 0 | 0.11 | 0.02 | | map-closure | 4.91 | 0.00 | 0 | 4.91 | 0.12 | | nbody | 1.47 | 0.17 | 1 | 1.64 | 0.08 | | pack-unpack | 0.29 | 0.02 | 1 | 0.31 | 0.01 | | pack-unpack-old | 0.43 | 0.05 | 3 | 0.48 | 0.01 | | pcase | 1.84 | 0.00 | 0 | 1.84 | 0.07 | | pidigits | 3.16 | 0.94 | 17 | 4.11 | 0.10 | | scroll | 0.58 | 0.00 | 0 | 0.58 | 0.00 | | smie | 1.40 | 0.04 | 2 | 1.44 | 0.06 | |--------------------+----------------+------------+---------+-------------+-----------------| | total | 25.38 | 1.62 | 45 | 27.00 | 0.32 | About ~10% improvement, with each individual benchmark being faster. Note how fibn test takes 0.00 seconds. It is limited to fixnum range. > Actually it is a bit of a bummer to the community since Emacs > is like THE portal into Lisp. We should have the best Lisp in > the business, and I don't see why not? Emacs + SBCL + CL + > Elisp anyone? This is a balancing act. Elisp is tailored for Emacs as an editor. So, trade-offs are inevitable. I am skeptical about Elisp overperforming CL. But it does not mean that we should not try to improve things. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at