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

From: Stephen Berman <[email-masked]>
Date: Fri, 01 Mar 2024 20:36:16 +0100

On Fri, 01 Mar 2024 18:34:30 +0200 Eli Zaretskii <[email-masked]> wrote:

>> From: Stephen Berman <[email-masked]>
>> Cc: [email-masked],  [email-masked],  [email-masked]
>> Date: Fri, 01 Mar 2024 14:53:18 +0100
>> 
>> On Fri, 01 Mar 2024 15:41:24 +0200 Eli Zaretskii <[email-masked]> wrote:
>> 
>> >> That says almost all memory and CPU are consumed by `build-sieve':
>> >
>> > This is skewed, use cpu profiling instead of "memory" profiling.
>> 
>> Ah, ok.
>> 
>> >> But I don't see how that bears on the difference between native and byte
>> >> compilation in my timings versus yours and Andrea's.
>> >
>> > My suggestion was to compare profiles in the byte-compiled and
>> > native-compiled cases.
>> >
>> > Btw, are you running both cases in the same session?  If so, don't:
>> > restart Emacs and run the other case instead.
>> 
>> Ok, I've now done that.  Here's the report for the run with native
>> compilation:
>> 
>>        12599  95% - command-execute
>>        12487  95%  - funcall-interactively
>>        12486  95%   - eval-expression
>>        12485  95%    - #<compiled -0x5db3e1955cb81d1>
>>        12485  95%     - #<compiled -0x8a5cf032951a0fe>
>>        12480  95%      - eval
>>        12480  95%       - progn
>>        12367  94%        - benchmark-call
>>        12367  94%         - #<lambda 0x8c97b8cb7bd82>
>>        12367  94%            build-sieve
>>          113   0%        - emacs-lisp-native-compile-and-load
>>          113   0%         - emacs-lisp-native-compile
>>          113   0%          - native-compile
>>           79   0%           - comp--native-compile
>>           37   0%            - comp--fwprop
>
> Why are subroutines of native-compilation in the profile?

I mistakenly used emacs-lisp-native-compile-and-load because its doc
string says "Native-compile the current buffer’s file (if it has
changed), then load it", and since it hadn't changed, I concluded
(apparently wrongly) that it would just be loaded.  Also, I didn't
realize you can load an .eln file just like you can an .el or .elc file.
Now I've done the profile after loading the .eln file and running
(benchmark-run nil (build-sieve (expt 10 8))).  The timing was
nevertheless practical the same as before:

(12.527129893 1 0.340515292)

Here's the profile report:

       12253  96% - command-execute
       12195  96%  - funcall-interactively
       12193  96%   - eval-expression
       12193  96%    - #<compiled -0x5db3e1955cb81d1>
       12193  96%     - #<compiled 0xfed2db7b0724d71>
       12187  96%      - eval
       12187  96%       - benchmark-call
       12184  96%        - #<lambda 0x833a720aa0822>
       12184  96%           build-sieve
           3   0%        - time-since
           1   0%         - byte-code
           1   0%            require
           6   0%      - macroexpand-all
           6   0%       - macroexp--expand-all
           6   0%        - macroexp-macroexpand
           6   0%           macroexpand-1
           2   0%     execute-extended-command
          58   0%  - byte-code
          35   0%   - read-extended-command
          35   0%    - read-extended-command-1
          35   0%     - completing-read-default
          12   0%        redisplay_internal (C function)
           1   0%        minibuffer-mode
          23   0%   - read--expression
           8   0%      redisplay_internal (C function)
           2   0%    - command-execute
           2   0%     - funcall-interactively
           2   0%      - yank
           2   0%       - current-kill
           2   0%        - gui-selection-value
           1   0%         - gui--selection-value-internal
           1   0%          - gui-get-selection
           1   0%           - gui-backend-get-selection
           1   0%            - apply
           1   0%             - #<compiled 0xb78982bfc8d3cfc>
           1   0%                x-get-selection-internal
           1   0%         - gui--set-last-clipboard-selection
           1   0%          - gui-backend-get-selection
           1   0%           - apply
           1   0%            - #<compiled 0xb78982bfc8d3cfc>
           1   0%               x-get-selection-internal
           1   0%    - timer-event-handler
           1   0%     - apply
           1   0%      - show-paren-function
           1   0%         show-paren--default
         351   2%   Automatic GC
          26   0%   redisplay_internal (C function)
          21   0% + timer-event-handler
          11   0% + ...

Steve Berman