Subject: Re: bug#52298: 29.0.50; Frequent redisplay cycles induced by c-type-finder-timer-func timer in CC Mode

From: Eli Zaretskii <[email-masked]>
Date: Thu, 09 Dec 2021 22:38:32 +0200

> Date: Thu, 9 Dec 2021 20:11:32 +0000
> Cc: [email-masked], [email-masked]
> From: Alan Mackenzie <[email-masked]>
> 
> >       debug_method_add (w, "try_window_id %d", tem);
> 
> > you will realize that redisplay called try_window_id, which means it
> > was working too hard: since nothing has changed in the buffer, and
> > even point didn't move, it should have succeeded in the call to
> > try_cursor_movement, which is before it.  So something prevented
> > try_cursor_movement from succeeding in this case, and kept preventing
> > that for full 4 minutes after the file was visited.  The question is:
> > what is that something that causes try_cursor_movement to fail?
> 
> The timer function is setting `fontified' text properties to nil.  It is
> doing this inside a with-silent-modifications.  (Sorry I didn't answer
> this question yesterday evening; I should have done.)
> 
> Have I misunderstood this action?  I thought that merely setting the
> `fontified' text property to nil on a part of the buffer doesn't
> instantaneously trigger redisplay (except by the calling of
> after-change-functions, which is here inactive due to
> `with-silent-modifications'), even if that part of the buffer is
> currently displayed in a window.

It seems the reason is not the 'fontified' property, it's the
'c-is-sws' property that c-forward-sws puts on the buffer text.  I
show the backtrace below.  There's also the 'c-type' property that
c-get-fontification-context puts; see the second backtrace below.

Both of these are called from the timer function.  Are they using
with-silent-modifications?

The result of this is that the buffer's modification tick is increased
all the time, and redisplay_window then decides that the current glyph
matrix is not up-to-date, which means it must work harder to decide
how to redisplay this window.

Here are the two backtraces I promised:

#0  0x013118d6 in modiff_incr (a=0x6ee5310) at lisp.h:3552
#1  0x0131203e in modify_text_properties (buffer=XIL(0xa000000006ee50a0),
    start=make_fixnum(39237), end=make_fixnum(39238)) at textprop.c:91
#2  0x01316a2b in add_text_properties_1 (start=make_fixnum(39237),
    end=make_fixnum(39238), properties=XIL(0xc00000000082b538),
    object=XIL(0xa000000006ee50a0), set_type=TEXT_PROPERTY_REPLACE,
    destructive=true) at textprop.c:1224
#3  0x01316ef0 in Fadd_text_properties (start=make_fixnum(39237),
    end=make_fixnum(39238), properties=XIL(0xc00000000082b538), object=XIL(0))
    at textprop.c:1296
#4  0x01316fcf in Fput_text_property (start=make_fixnum(39237),
    end=make_fixnum(39238), property=XIL(0x56056f0), value=XIL(0x30),
    object=XIL(0)) at textprop.c:1314
#5  0x012670c5 in funcall_subr (subr=0x17216a0 <Sput_text_property>,
    numargs=4, args=0x82b790) at eval.c:3152
#6  0x012669b1 in Ffuncall (nargs=5, args=0x82b788) at eval.c:3065
#7  0x012d3314 in exec_byte_code (bytestr=XIL(0x8000000006e55e40),
    vector=XIL(0xa000000006e55068), maxdepth=make_fixnum(19),
    args_template=make_fixnum(0), nargs=0, args=0x82c0a8) at bytecode.c:632
#8  0x012674f6 in fetch_and_exec_byte_code (fun=XIL(0xa000000006e551e8),
    syms_left=make_fixnum(0), nargs=0, args=0x82c0a8) at eval.c:3189
#9  0x01267a73 in funcall_lambda (fun=XIL(0xa000000006e551e8), nargs=0,
    arg_vector=0x82c0a8) at eval.c:3270
#10 0x01266a21 in Ffuncall (nargs=1, args=0x82c0a0) at eval.c:3069
#11 0x012d3314 in exec_byte_code (bytestr=XIL(0x80000000074e9df8),
    vector=XIL(0xa0000000074e1888), maxdepth=make_fixnum(14),
    args_template=make_fixnum(257), nargs=1, args=0x82c7e0) at bytecode.c:632
#12 0x012674f6 in fetch_and_exec_byte_code (fun=XIL(0xa0000000074e1990),
    syms_left=make_fixnum(257), nargs=1, args=0x82c7d8) at eval.c:3189
#13 0x01267a73 in funcall_lambda (fun=XIL(0xa0000000074e1990), nargs=1,
    arg_vector=0x82c7d8) at eval.c:3270
#14 0x01266a21 in Ffuncall (nargs=2, args=0x82c7d0) at eval.c:3069
#15 0x012d3314 in exec_byte_code (bytestr=XIL(0x8000000006eedf18),
    vector=XIL(0xa0000000074e1b58), maxdepth=make_fixnum(7),
    args_template=make_fixnum(514), nargs=2, args=0x82cde0) at bytecode.c:632
#16 0x012674f6 in fetch_and_exec_byte_code (fun=XIL(0xa0000000074e1bc8),
    syms_left=make_fixnum(514), nargs=2, args=0x82cdd0) at eval.c:3189
#17 0x01267a73 in funcall_lambda (fun=XIL(0xa0000000074e1bc8), nargs=2,
    arg_vector=0x82cdd0) at eval.c:3270
#18 0x01266a21 in Ffuncall (nargs=3, args=0x82cdc8) at eval.c:3069
#19 0x012d3314 in exec_byte_code (bytestr=XIL(0x8000000006eedf48),
    vector=XIL(0xa00000000753e690), maxdepth=make_fixnum(5),
    args_template=make_fixnum(257), nargs=1, args=0x82d390) at bytecode.c:632
#20 0x012674f6 in fetch_and_exec_byte_code (fun=XIL(0xa00000000753e6b0),
    syms_left=make_fixnum(257), nargs=1, args=0x82d388) at eval.c:3189
#21 0x01267a73 in funcall_lambda (fun=XIL(0xa00000000753e6b0), nargs=1,
    arg_vector=0x82d388) at eval.c:3270
#22 0x01266a21 in Ffuncall (nargs=2, args=0x82d380) at eval.c:3069
#23 0x01265cc4 in call1 (fn=XIL(0xa00000000753e6b0), arg1=XIL(0x5c690a0))
    at eval.c:2925
#24 0x0127bd8f in mapcar1 (leni=1, vals=0x0, fn=XIL(0xa00000000753e6b0),
    seq=XIL(0xc000000006f4fe30)) at fns.c:2848
#25 0x0127c4eb in Fmapc (function=XIL(0xa00000000753e6b0),
    sequence=XIL(0xc000000006f4fe30)) at fns.c:2925
#26 0x01266f6c in funcall_subr (subr=0x171fa20 <Smapc>, numargs=2,
    args=0x82d688) at eval.c:3142
#27 0x012669b1 in Ffuncall (nargs=3, args=0x82d680) at eval.c:3065
#28 0x012d3314 in exec_byte_code (bytestr=XIL(0x8000000006eedf38),
    vector=XIL(0xa0000000074e1c48), maxdepth=make_fixnum(11),
    args_template=make_fixnum(514), nargs=2, args=0x82dca0) at bytecode.c:632
#29 0x012674f6 in fetch_and_exec_byte_code (fun=XIL(0xa0000000074e1c70),
    syms_left=make_fixnum(514), nargs=2, args=0x82dc90) at eval.c:3189
#30 0x01267a73 in funcall_lambda (fun=XIL(0xa0000000074e1c70), nargs=2,
    arg_vector=0x82dc90) at eval.c:3270
#31 0x01266a21 in Ffuncall (nargs=3, args=0x82dc88) at eval.c:3069
#32 0x012d3314 in exec_byte_code (bytestr=XIL(0x80000000074a3398),
    vector=XIL(0xa000000006f6c918), maxdepth=make_fixnum(11),
    args_template=make_fixnum(0), nargs=0, args=0x82e530) at bytecode.c:632
#33 0x012674f6 in fetch_and_exec_byte_code (fun=XIL(0xa000000006f37d58),
    syms_left=make_fixnum(0), nargs=0, args=0x82e530) at eval.c:3189
#34 0x01267a73 in funcall_lambda (fun=XIL(0xa000000006f37d58), nargs=0,
    arg_vector=0x82e530) at eval.c:3270
#35 0x01266a21 in Ffuncall (nargs=1, args=0x82e528) at eval.c:3069
#36 0x01264f28 in Fapply (nargs=2, args=0x82e528) at eval.c:2648
#37 0x01266e59 in funcall_subr (subr=0x171eda0 <Sapply>, numargs=2,
    args=0x82e528) at eval.c:3120
#38 0x012669b1 in Ffuncall (nargs=3, args=0x82e520) at eval.c:3065
#39 0x012d3314 in exec_byte_code (bytestr=XIL(0x80000000061333c4),
    vector=XIL(0xa000000006133294), maxdepth=make_fixnum(10),
    args_template=make_fixnum(257), nargs=1, args=0x82ebb0) at bytecode.c:632
#40 0x012674f6 in fetch_and_exec_byte_code (fun=XIL(0xa000000006133264),
    syms_left=make_fixnum(257), nargs=1, args=0x82eba8) at eval.c:3189
#41 0x01267a73 in funcall_lambda (fun=XIL(0xa000000006133264), nargs=1,
    arg_vector=0x82eba8) at eval.c:3270
#42 0x01266a21 in Ffuncall (nargs=2, args=0x82eba0) at eval.c:3069
#43 0x01265cc4 in call1 (fn=XIL(0xf120), arg1=XIL(0xa00000000753e580))
    at eval.c:2925
#44 0x0117447a in timer_check_2 (timers=XIL(0), idle_timers=XIL(0))
    at keyboard.c:4374
#45 0x01174675 in timer_check () at keyboard.c:4436
#46 0x01171ed6 in readable_events (flags=1) at keyboard.c:3448
#47 0x0117c519 in get_input_pending (flags=1) at keyboard.c:6924
#48 0x0118878d in detect_input_pending_run_timers (do_display=false)
    at keyboard.c:10454
#49 0x0116e798 in read_char (commandflag=1, map=XIL(0xc000000007629a30),
    prev_event=XIL(0), used_mouse_menu=0x82f45f, end_time=0x0)
    at keyboard.c:2813
#50 0x01185e58 in read_key_sequence (keybuf=0x82f760, prompt=XIL(0),
    dont_downcase_last=false, can_return_switch_frame=true,
    fix_current_buffer=true, prevent_redisplay=false) at keyboard.c:9631
#51 0x0116924a in command_loop_1 () at keyboard.c:1393
#52 0x0126082e in internal_condition_case (bfun=0x1168b27 <command_loop_1>,
    handlers=XIL(0x90), hfun=0x1167b25 <cmd_error>) at eval.c:1492
#53 0x01168594 in command_loop_2 (handlers=XIL(0x90)) at keyboard.c:1134
#54 0x0125f6bf in internal_catch (tag=XIL(0xf3f0),
    func=0x116855d <command_loop_2>, arg=XIL(0x90)) at eval.c:1223
#55 0x01168517 in command_loop () at keyboard.c:1112
#56 0x0116758d in recursive_edit_1 () at keyboard.c:721
#57 0x01167823 in Frecursive_edit () at keyboard.c:804
#58 0x01162e9f in main (argc=2, argv=0xa42a10) at emacs.c:2409

Lisp Backtrace:
"put-text-property" (0x82b790)
"c-forward-sws" (0x82c0a8)
"c-fl-decl-start" (0x82c7d8)
"c-context-expand-fl-region" (0x82cdd0)
0x753e6b0 PVEC_COMPILED
"mapc" (0x82d688)
"c-before-context-fl-expand-region" (0x82dc90)
"c-type-finder-timer-func" (0x82e530)
"apply" (0x82e528)
"timer-event-handler" (0x82eba8)
(gdb) fr 4
#4  0x01316fcf in Fput_text_property (start=make_fixnum(39237),
    end=make_fixnum(39238), property=XIL(0x56056f0), value=XIL(0x30),
    object=XIL(0)) at textprop.c:1314
1314      Fadd_text_properties (start, end, properties, object);
(gdb) pp property
c-is-sws

----------------------------------------------------------------------

#0  0x013118d6 in modiff_incr (a=0x6ee5310) at lisp.h:3552
#1  0x0131203e in modify_text_properties (buffer=XIL(0xa000000006ee50a0),
    start=make_fixnum(39339), end=make_fixnum(39340)) at textprop.c:91
#2  0x01316a2b in add_text_properties_1 (start=make_fixnum(39339),
    end=make_fixnum(39340), properties=XIL(0xc00000000082b258),
    object=XIL(0xa000000006ee50a0), set_type=TEXT_PROPERTY_REPLACE,
    destructive=true) at textprop.c:1224
#3  0x01316ef0 in Fadd_text_properties (start=make_fixnum(39339),
    end=make_fixnum(39340), properties=XIL(0xc00000000082b258), object=XIL(0))
    at textprop.c:1296
#4  0x01316fcf in Fput_text_property (start=make_fixnum(39339),
    end=make_fixnum(39340), property=XIL(0x57a2ff8), value=XIL(0x566adc8),
    object=XIL(0)) at textprop.c:1314
#5  0x012670c5 in funcall_subr (subr=0x17216a0 <Sput_text_property>,
    numargs=4, args=0x82b478) at eval.c:3152
#6  0x012669b1 in Ffuncall (nargs=5, args=0x82b470) at eval.c:3065
#7  0x012d3314 in exec_byte_code (bytestr=XIL(0x80000000074a3208),
    vector=XIL(0xa000000006f37550), maxdepth=make_fixnum(10),
    args_template=make_fixnum(770), nargs=3, args=0x82bca0) at bytecode.c:632
#8  0x012674f6 in fetch_and_exec_byte_code (fun=XIL(0xa000000006f376e8),
    syms_left=make_fixnum(770), nargs=3, args=0x82bc88) at eval.c:3189
#9  0x01267a73 in funcall_lambda (fun=XIL(0xa000000006f376e8), nargs=3,
    arg_vector=0x82bc88) at eval.c:3270
#10 0x01266a21 in Ffuncall (nargs=4, args=0x82bc80) at eval.c:3069
#11 0x012d3314 in exec_byte_code (bytestr=XIL(0x80000000074a3348),
    vector=XIL(0xa000000007581b18), maxdepth=make_fixnum(8),
    args_template=make_fixnum(770), nargs=3, args=0x82c348) at bytecode.c:632
#12 0x012674f6 in fetch_and_exec_byte_code (fun=XIL(0xa000000007581bc8),
    syms_left=make_fixnum(770), nargs=3, args=0x82c330) at eval.c:3189
#13 0x01267a73 in funcall_lambda (fun=XIL(0xa000000007581bc8), nargs=3,
    arg_vector=0x82c330) at eval.c:3270
#14 0x01266a21 in Ffuncall (nargs=4, args=0x82c328) at eval.c:3069
#15 0x012d3314 in exec_byte_code (bytestr=XIL(0x8000000006f7a9f0),
    vector=XIL(0xa0000000065a7a50), maxdepth=make_fixnum(23),
    args_template=make_fixnum(1028), nargs=4, args=0x82d658) at bytecode.c:632
#16 0x012674f6 in fetch_and_exec_byte_code (fun=XIL(0xa0000000065a7c68),
    syms_left=make_fixnum(1028), nargs=4, args=0x82d638) at eval.c:3189
#17 0x01267a73 in funcall_lambda (fun=XIL(0xa0000000065a7c68), nargs=4,
    arg_vector=0x82d638) at eval.c:3270
#18 0x01266a21 in Ffuncall (nargs=5, args=0x82d630) at eval.c:3069
#19 0x012d3314 in exec_byte_code (bytestr=XIL(0x80000000074a3338),
    vector=XIL(0xa000000006f37c50), maxdepth=make_fixnum(18),
    args_template=make_fixnum(514), nargs=2, args=0x82dca8) at bytecode.c:632
#20 0x012674f6 in fetch_and_exec_byte_code (fun=XIL(0xa000000006f37c98),
    syms_left=make_fixnum(514), nargs=2, args=0x82dc98) at eval.c:3189
#21 0x01267a73 in funcall_lambda (fun=XIL(0xa000000006f37c98), nargs=2,
    arg_vector=0x82dc98) at eval.c:3270
#22 0x01266a21 in Ffuncall (nargs=3, args=0x82dc90) at eval.c:3069
#23 0x012d3314 in exec_byte_code (bytestr=XIL(0x80000000074a3398),
    vector=XIL(0xa000000006f6c918), maxdepth=make_fixnum(11),
    args_template=make_fixnum(0), nargs=0, args=0x82e530) at bytecode.c:632
#24 0x012674f6 in fetch_and_exec_byte_code (fun=XIL(0xa000000006f37d58),
    syms_left=make_fixnum(0), nargs=0, args=0x82e530) at eval.c:3189
#25 0x01267a73 in funcall_lambda (fun=XIL(0xa000000006f37d58), nargs=0,
    arg_vector=0x82e530) at eval.c:3270
#26 0x01266a21 in Ffuncall (nargs=1, args=0x82e528) at eval.c:3069
#27 0x01264f28 in Fapply (nargs=2, args=0x82e528) at eval.c:2648
#28 0x01266e59 in funcall_subr (subr=0x171eda0 <Sapply>, numargs=2,
    args=0x82e528) at eval.c:3120
#29 0x012669b1 in Ffuncall (nargs=3, args=0x82e520) at eval.c:3065
#30 0x012d3314 in exec_byte_code (bytestr=XIL(0x80000000061333c4),
    vector=XIL(0xa000000006133294), maxdepth=make_fixnum(10),
    args_template=make_fixnum(257), nargs=1, args=0x82ebb0) at bytecode.c:632
#31 0x012674f6 in fetch_and_exec_byte_code (fun=XIL(0xa000000006133264),
    syms_left=make_fixnum(257), nargs=1, args=0x82eba8) at eval.c:3189
#32 0x01267a73 in funcall_lambda (fun=XIL(0xa000000006133264), nargs=1,
    arg_vector=0x82eba8) at eval.c:3270
#33 0x01266a21 in Ffuncall (nargs=2, args=0x82eba0) at eval.c:3069
#34 0x01265cc4 in call1 (fn=XIL(0xf120), arg1=XIL(0xa00000000753e580))
    at eval.c:2925
#35 0x0117447a in timer_check_2 (timers=XIL(0), idle_timers=XIL(0))
    at keyboard.c:4374
#36 0x01174675 in timer_check () at keyboard.c:4436
#37 0x01171ed6 in readable_events (flags=1) at keyboard.c:3448
#38 0x0117c519 in get_input_pending (flags=1) at keyboard.c:6924
#39 0x0118878d in detect_input_pending_run_timers (do_display=false)
    at keyboard.c:10454
#40 0x0116e798 in read_char (commandflag=1, map=XIL(0xc000000007629a30),
    prev_event=XIL(0), used_mouse_menu=0x82f45f, end_time=0x0)
    at keyboard.c:2813
#41 0x01185e58 in read_key_sequence (keybuf=0x82f760, prompt=XIL(0),
    dont_downcase_last=false, can_return_switch_frame=true,
    fix_current_buffer=true, prevent_redisplay=false) at keyboard.c:9631
#42 0x0116924a in command_loop_1 () at keyboard.c:1393
#43 0x0126082e in internal_condition_case (bfun=0x1168b27 <command_loop_1>,
    handlers=XIL(0x90), hfun=0x1167b25 <cmd_error>) at eval.c:1492
#44 0x01168594 in command_loop_2 (handlers=XIL(0x90)) at keyboard.c:1134
#45 0x0125f6bf in internal_catch (tag=XIL(0xf3f0),
    func=0x116855d <command_loop_2>, arg=XIL(0x90)) at eval.c:1223
#46 0x01168517 in command_loop () at keyboard.c:1112
#47 0x0116758d in recursive_edit_1 () at keyboard.c:721
#48 0x01167823 in Frecursive_edit () at keyboard.c:804
#49 0x01162e9f in main (argc=2, argv=0xa42a10) at emacs.c:2409

Lisp Backtrace:
"put-text-property" (0x82b478)
"c-get-fontification-context" (0x82bc88)
0x7581bc8 PVEC_COMPILED
"c-find-decl-spots" (0x82d638)
"c-find-types-background" (0x82dc98)
"c-type-finder-timer-func" (0x82e530)
"apply" (0x82e528)
"timer-event-handler" (0x82eba8)
(gdb) fr 4
#4  0x01316fcf in Fput_text_property (start=make_fixnum(39339),
    end=make_fixnum(39340), property=XIL(0x57a2ff8), value=XIL(0x566adc8),
    object=XIL(0)) at textprop.c:1314
1314      Fadd_text_properties (start, end, properties, object);
(gdb) pp property
c-type