Subject: bug#75357: [scratch/elisp-benchmarks] elb-scroll window size assumption breaks on repeated runs

From: Stefan Monnier <[email-masked]>
Date: Mon, 06 Jan 2025 09:24:13 -0500

>> On scratch/elisp-benchmarks, the following emacs -Q invocation:
>>
>> ./src/emacs --batch -Q -l ./elisp-benchmarks/elisp-benchmarks.el --eval '(progn (elisp-benchmarks-run "scroll" t 1) (elisp-benchmarks-run "scroll" t 1))'
>>
>> produces a fatal Lisp error, attempting to invoke the debugger in a
>> non-interactive session:
>>
>> Loading /home/pip/emacs-elisp-benchmarks/elisp-benchmarks/benchmarks/elb-smie...
>> Window size: 19 x 80
>> Debugger entered--Lisp error: (error "Window size not as stipulated by the benchmark")
>>   signal(error ("Window size not as stipulated by the benchmark"))
>>   error("Window size not as stipulated by the benchmark")
>>   elb-scroll-entry()
>
> I'm not sure this is a bug as we want always to run the benchmark from a
> known state, anyway adding Stefan as he's the author of the benchmark.

Sounds like something has changed in Emacs's C code, or maybe it's
something in some system-depend code?
`elb-scroll` cares about the window size because it's a benchmark that
is influenced by (and thus partly measures) the redisplay:

    (unless (and noninteractive (not (boundp 'redisplay-skip-initial-frame)))
      (defun elb-scroll-entry ()
        ;; FIXME: This relies on `elb-smie.el' being compiled already which is
        ;; not necessarily the case if we're only running some of the benchmarks.
        (load (expand-file-name "elb-smie" elb-bench-directory) nil 'nomessage)
        (setq redisplay-skip-initial-frame nil)
        (with-temp-buffer
          (rename-buffer (generate-new-buffer-name "elb-scroll"))
          (switch-to-buffer (current-buffer))
          (insert-file-contents (expand-file-name
                                 "../resources/xmenu.c" elb-bench-directory))
          (redisplay 'force) ;; Refresh the window dimensions.
          (enlarge-window (- 23 (window-height)))
          (enlarge-window (- 80 (window-width)) 'horiz)
          (redisplay 'force) ;; Refresh the window dimensions.
          (unless (and (equal 23 (window-height))
                       (equal 80 (window-width)))
            (error "Window size %S x %S not as stipulated by the benchmark"
                    (window-height) (window-width)))
          (dotimes (_ 10)
            (elb-smie-mode)
            (goto-char (point-min))
            (condition-case nil
                (while t (scroll-up nil) (redisplay 'force))
              (end-of-buffer nil))))))

Try and figure out why window size is 19x80 after

          (enlarge-window (- 23 (window-height)))
          (enlarge-window (- 80 (window-width)) 'horiz)

- Stefan