Subject: bug#38407: 27.0.50; infinite loop with display of large file without newlines

From: Robert Pluim <[email-masked]>
Date: Mon, 02 Dec 2019 11:27:10 +0100

>>>>> On Sun, 01 Dec 2019 19:45:11 +0200, Eli Zaretskii <[email-masked]> said:

    >> However, for me, bidi-inhibit-bpa comprehensively deals to that.

    Eli> Down to 1 min here.

    Eli> One other observation is that the first time you do that in a session
    Eli> after visiting the file, it takes much longer than the subsequent
    Eli> times.  Here, the second M-> takes 5 min with bidi-inhibit-bpa nil and
    Eli> just 17 sec with it non-nil.

    Eli> So I think some of this time is spent doing something we do once,
    Eli> maybe loading fonts or something (this file has a lot of different
    Eli> scripts).

I donʼt see any real difference between the first and second M-> with
bidi-inhibit-bpa t, so I didnʼt benchmark that, but I can if you want.

    Eli> It would be interesting to run perf and compare its output with
    Eli> bidi-inhibit-bpa nil and non-nil.  Maybe the performance hit due to
    Eli> visual-line-mode is because of some code that could be optimized, or
    Eli> maybe (gasp!) even a bug.  The difference between the first and
    Eli> subsequent moves is also interesting to time.

    Eli> I don't have access to a GUI system where I can run perf, so could
    Eli> someone please do these measurements and post the resulting profiles?

Iʼve done two runs, with visual-line-mode enabled, and bidi-inhibit-bpa
t/nil. Gzipped text versions of 'perf report' attached.

(Aside: why does char_table_ref check ASCII_CHAR_P again, when
CHAR_TABLE_REF already does that?)

bidi-inhibit-bpa t:

# Overhead  Command       Shared Object                  Symbol
# ........  ............  .............................  ............................................
#
    11.21%  emacs         emacs                          [.] composition_compute_stop_pos
     6.11%  emacs         emacs                          [.] CHAR_TABLE_REF
     5.65%  emacs         emacs                          [.] mark_object
     4.17%  emacs         emacs                          [.] re_match_2_internal
     2.85%  emacs         emacs                          [.] lookup_char_property
     1.82%  emacs         emacs                          [.] next_interval
     1.74%  emacs         emacs                          [.] Fassq
     1.65%  emacs         emacs                          [.] compute_stop_pos
     1.63%  emacs         emacs                          [.] find_interval
     1.19%  emacs         libc-2.29.so                   [.] _IO_getc
     1.15%  emacs         libc-2.29.so                   [.] __memmove_avx_unaligned_erms
     1.12%  emacs         emacs                          [.] exec_byte_code
     1.02%  emacs         emacs                          [.] move_it_in_display_line_to
     1.02%  emacs         emacs                          [.] sub_char_table_ref
     0.92%  emacs         ld-2.29.so                     [.] do_lookup_x
     0.90%  emacs         emacs                          [.] buf_bytepos_to_charpos

bidi-inhibit-bpa nil:

# Overhead  Command       Shared Object                  Symbol
# ........  ............  .............................  ..........................................................
#
    96.59%  emacs         libc-2.29.so                   [.] __memmove_avx_unaligned_erms
     0.22%  emacs         emacs                          [.] mark_object
     0.17%  emacs         emacs                          [.] composition_compute_stop_pos
     0.12%  emacs         emacs                          [.] re_match_2_internal
     0.12%  emacs         emacs                          [.] bidi_resolve_explicit
     0.09%  emacs         emacs                          [.] CHAR_TABLE_REF
     0.07%  emacs         emacs                          [.] lookup_char_property
     0.06%  emacs         emacs                          [.] bidi_fetch_char
     0.05%  emacs         emacs                          [.] find_interval
     0.05%  emacs         libc-2.29.so                   [.] _IO_getc
     0.04%  emacs         emacs                          [.] move_it_in_display_line_to
     0.04%  emacs         emacs                          [.] bidi_cache_search.constprop.0
     0.04%  emacs         emacs                          [.] exec_byte_code
     0.04%  emacs         emacs                          [.] next_interval
     0.04%  emacs         emacs                          [.] mark_char_table
     0.04%  emacs         emacs                          [.] pdumper_marked_p_implq
     0.04%  emacs         ld-2.29.so                     [.] do_lookup_x
     0.03%  emacs         libc-2.29.so                   [.] __strchr_avx2
     0.03%  emacs         emacs                          [.] rpl_re_search_2
     0.03%  emacs         emacs                          [.] sub_char_table_ref
     0.03%  emacs         emacs                          [.] bidi_cache_iterator_state