Subject: bug#18522: 24.4.50; mapcar is very slow

From: Eli Zaretskii <[email-masked]>
Date: Wed, 24 Feb 2016 22:26:15 +0200

> From: Peter Münster <[email-masked]>
> Cc: [email-masked],  [email-masked],  [email-masked]
> Date: Wed, 24 Feb 2016 21:03:41 +0100
> 
> --8<---------------cut here---------------start------------->8---
>        │                 /* If this variable is not always local in all buffers,
>        │                    set it in the buffers that don't nominally have a local value.  */
>        │                 if (idx > 0)
>        │     ↑ jle    95
>        │                   {
>        │                     struct buffer *b;
>        │                     int i = 0;
>        │                     FOR_EACH_BUFFER (b)
>   0.08 │       mov    all_buffers,%rcx
>        │       test   %rcx,%rcx
>        │     ↓ je     180
>        │                     {
>        │                       i++;
>        │                       if (!PER_BUFFER_VALUE_P (b, idx))
>   0.02 │       cmp    last_per_buffer_idx,%edx
>        │     ↓ jge    160
>        │                   {
>        │                     struct buffer *b;
>        │                     int i = 0;
>        │                     FOR_EACH_BUFFER (b)
>        │                     {
>        │                       i++;
>        │       mov    $0x1,%edx
>   0.02 │     ↓ jmp    f3
>        │       nop
>  15.24 │ f0:   add    $0x1,%edx
>        │                       if (!PER_BUFFER_VALUE_P (b, idx))
>  14.02 │ f3:   cmpb   $0x0,0x320(%rcx,%rax,1)
>  10.65 │     ↓ jne    101
>        │     set_per_buffer_value():
>        │     }
>        │
>        │     INLINE void
>        │     set_per_buffer_value (struct buffer *b, int offset, Lisp_Object value)
>        │     {
>        │       *(Lisp_Object *)(offset + (char *) b) = value;
>  14.11 │       mov    %rbp,(%rcx,%rsi,1)
>        │     Fset_default():
>        │                    set it in the buffers that don't nominally have a local value.  */
>        │                 if (idx > 0)
>        │                   {
>        │                     struct buffer *b;
>        │                     int i = 0;
>        │                     FOR_EACH_BUFFER (b)
>  14.36 │101:   mov    0x2d8(%rcx),%rcx
>  21.80 │       test   %rcx,%rcx
>   5.16 │     ↑ jne    f0
>        │                     {
>        │                       i++;
>        │                       if (!PER_BUFFER_VALUE_P (b, idx))
>        │                         set_per_buffer_value (b, offset, value);
>        │                     }
>        │                     fprintf(stderr, "XXXXX: %d\n", i);
>   0.00 │10d:   mov    stderr@@GLIBC_2.2.5,%rdi
>   2.18 │       mov    $0x5e90e5,%esi
>        │       xor    %eax,%eax
>        │     → callq  fprintf@plt
>        │     ↑ jmpq   95
>        │       nop
> --8<---------------cut here---------------end--------------->8---

Most of the time is spent in the loop over the buffers.

So I guess avoiding binding case-fold-search in parse-time-string
should make the problem go away?