Subject: bug#69480: Emacs Lisp needs, for its great 'native-compile', 'declare' and 'the' for fixnums and arrays.

From: Eli Zaretskii <[email-masked]>
Date: Fri, 01 Mar 2024 14:34:36 +0200

> From: Stephen Berman <[email-masked]>
> Cc: Robert Boyer <[email-masked]>,  [email-masked]
> Date: Fri, 01 Mar 2024 12:28:30 +0100
> 
> On Thu, 29 Feb 2024 22:10:27 +0200 Eli Zaretskii <[email-masked]> wrote:
> 
> > It takes 16.7 sec on my system.
> 
> I was curious to see how long it takes on my system, compared to the
> byte-compiled and uncompiled files, and the results surprised me.
> First, I visited the file eratosthenes.el, ran `eval-buffer' and then
> `M-: (benchmark-run nil (build-sieve (expt 10 8)))', with this result:
> 
> (143.326808051 1 0.344846223)
> 
> Then I ran `M-: (progn (emacs-lisp-native-compile-and-load)
> (benchmark-run nil (build-sieve (expt 10 8))))', with this result:
> 
> (37.457440511 1 0.36922945500000004)
> 
> The native compilation also produced a byte-compiled file
> eratosthenes.elc, so I then loaded that file and again ran `M-:
> (benchmark-run nil (build-sieve (expt 10 8)))', with this result:
> 
> (21.854069551000002 1 0.3595161699999999)
> 
> I was surprised that this was much faster than the run with native
> compilation, but I thought perhaps this was due to the time spent
> producing both the native and byte-compiled files (though more than 15
> seconds for that seemed unlikely), so I ran `M-: (progn
> (emacs-lisp-native-compile-and-load) (benchmark-run nil (build-sieve
> (expt 10 8))))' again, which just loaded the already native-compiled
> file (and updated its timestamp), but the result was practically the
> same as the first time:
> 
> (37.095767574 1 0.36986937500000017)
> 
> Why is the timing with native compilation so much slower than with byte
> compilation?

That's not what I see here (in an optimized build of Emacs 29.2).  On
my system, the byte-compiled version and the native-compiled version
yield almost the same times: 16.12 vs 16.5 sec.  The way native
compilation is currently implemented, whether it produces a
significant speedup depends on the actual Lisp code, and having the
same or even slightly slower performance is not unheard of.  So I
don't see anything unexpected on my system, at least in Emacs 29.

Adding Andrea, in case he has comments to this.