Subject: Re: bug#58558: 29.0.50; re-search-forward is slow in some buffers

From: Ihor Radchenko <[email-masked]>
Date: Tue, 13 Dec 2022 15:56:33 +0000

Eli Zaretskii <[email-masked]> writes:

>> I will look how to do it. Maybe perf probe.
>> I guess, it will be useful to compile Emacs with debug symbols at this
>> point.
>
> AFAIR, you can ask perf to profile a single function, and you can ask
> it to annotate the profile with the source code.

I now compiled Emacs with debug symbols, waited enough to see observable
increase in the benchmark-run timing, and recorded the perf data.

buf_bytepos_to_charpos is still on the top

    78.06%  emacs         emacs                       [.] buf_bytepos_to_charpos
     3.00%  emacs         emacs                       [.] re_match_2_internal
     1.05%  emacs         emacs                       [.] find_interval
     1.04%  emacs         emacs                       [.] CHAR_TABLE_REF_ASCII
     0.85%  emacs         emacs                       [.] make_lisp_symbol
     0.80%  emacs         emacs                       [.] re_search_2
     0.76%  emacs         emacs                       [.] builtin_lisp_symbol
     0.62%  emacs         emacs                       [.] PSEUDOVECTORP

The specific place in the code is:

perf annotate -s buf_bytepos_to_charpos 

        : 352    for (tail = BUF_MARKERS (b); tail; tail = tail->next)
    0.00 :   237e53: mov    -0xe8(%rbp),%rax
    0.00 :   237e5a: mov    0x2e8(%rax),%rax
    0.01 :   237e61: mov    0x80(%rax),%rax
    0.00 :   237e68: mov    %rax,-0xc0(%rbp)
    0.00 :   237e6f: jmp    237fc6 <buf_bytepos_to_charpos+0x7ba>
         : 353    {
         : 354    CONSIDER (tail->bytepos, tail->charpos);
    0.02 :   237e74: mov    -0xc0(%rbp),%rax
   47.07 :   237e7b: mov    0x28(%rax),%rax
    7.27 :   237e7f: mov    %rax,-0x38(%rbp)
    0.02 :   237e83: movl   $0x0,-0xc4(%rbp)
    9.05 :   237e8d: mov    -0x38(%rbp),%rax
    0.01 :   237e91: cmp    -0xf0(%rbp),%rax
    3.73 :   237e98: jne    237eb2 <buf_bytepos_to_charpos+0x6a6>
    0.00 :   237e9a: mov    -0xc0(%rbp),%rax
    0.00 :   237ea1: mov    0x20(%rax),%rax
    0.00 :   237ea5: mov    %rax,-0x28(%rbp)
    0.00 :   237ea9: mov    -0x28(%rbp),%rax
    0.00 :   237ead: jmp    2381cd <buf_bytepos_to_charpos+0x9c1>
    2.14 :   237eb2: mov    -0x38(%rbp),%rax
    1.87 :   237eb6: cmp    -0xf0(%rbp),%rax
    0.85 :   237ebd: jle    237ef5 <buf_bytepos_to_charpos+0x6e9>
    2.32 :   237ebf: mov    -0x38(%rbp),%rax
    0.04 :   237ec3: cmp    -0xb0(%rbp),%rax
    2.56 :   237eca: jge    237f29 <buf_bytepos_to_charpos+0x71d>

My guess: number of markers is growing somehow?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>