all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
blob 34cc6abd310bb23215d76569fd5c065f5f4ddd1a 12749 bytes (raw)
name: test/manual/noverlay/overlay-perf.el 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
 
;; -*- lexical-binding:t -*-

;; Copyright (C) 2015-2024 Free Software Foundation, Inc.

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.

;;; Code:

\f
;; +===================================================================================+
;; | Basic performance tests
;; +===================================================================================+

(perf-define-variable-test perf-make-overlay (n)
  (with-temp-buffer
    (overlay-recenter (point-min))
    (benchmark-run 1
      (dotimes (_ n)
        (make-overlay 1 1)))))

(perf-define-variable-test perf-make-overlay-continuous (n)
  (with-temp-buffer
    (perf-insert-text n)
    (overlay-recenter (point-max))
    (benchmark-run 1
      (dotimes (i n)
        (make-overlay i (1+ i))))))

(perf-define-variable-test perf-make-overlay-scatter (n)
  (with-temp-buffer
    (perf-insert-text n)
    (benchmark-run 1
      (perf-insert-overlays-scattered n))))

(perf-define-variable-test perf-delete-overlay (n)
  (with-temp-buffer
    (let ((ovls (cl-loop for i from 1 to n
                        collect (make-overlay 1 1))))
      (overlay-recenter (point-min))
      (benchmark-run 1
        (mapc #'delete-overlay ovls)))))

(perf-define-variable-test perf-delete-overlay-continuous (n)
  (with-temp-buffer
    (perf-insert-text n)
    (let ((ovls (cl-loop for i from 1 to n
                         collect (make-overlay i (1+ i)))))
      (overlay-recenter (point-min))
      (benchmark-run 1
        (mapc #'delete-overlay ovls)))))

(perf-define-variable-test perf-delete-overlay-scatter (n)
  (with-temp-buffer
    (perf-insert-text n)
    (let ((ovls (progn (perf-insert-overlays-scattered n)
                       (overlays-in (point-min) (point-max)))))
      (benchmark-run 1
        (mapc #'delete-overlay ovls)))))

(perf-define-variable-test perf-overlays-at (n)
  (with-temp-buffer
    (perf-insert-text n)
    (perf-insert-overlays-scattered n)
    (benchmark-run 1
      (dotimes (i (point-max))
        (overlays-at i)))))

(perf-define-variable-test perf-overlays-in (n)
  (with-temp-buffer
    (perf-insert-text n)
    (perf-insert-overlays-scattered n)
    (let ((len perf-insert-overlays-default-length))
      (benchmark-run 1
        (dotimes (i (- (point-max) len))
          (overlays-in i (+ i len)))))))

(perf-define-variable-test perf-insert-before (n)
  (with-temp-buffer
    (perf-insert-text n)
    (perf-insert-overlays-scattered n)
    (goto-char 1)
    (overlay-recenter (point-min))
    (benchmark-run 1
      (dotimes (_ (/ n 2))
        (insert ?X)))))

(perf-define-variable-test perf-insert-before-empty (n)
  (let ((perf-insert-overlays-default-length 0))
    (perf-insert-before n)))
(perf-define-variable-test perf-insert-after-empty (n)
  (let ((perf-insert-overlays-default-length 0))
    (perf-insert-after n)))
(perf-define-variable-test perf-insert-scatter-empty (n)
  (let ((perf-insert-overlays-default-length 0))
    (perf-insert-scatter n)))
(perf-define-variable-test perf-delete-before-empty (n)
  (let ((perf-insert-overlays-default-length 0))
    (perf-delete-before n)))
(perf-define-variable-test perf-delete-after-empty (n)
  (let ((perf-insert-overlays-default-length 0))
    (perf-delete-after n)))
(perf-define-variable-test perf-delete-scatter-empty (n)
  (let ((perf-insert-overlays-default-length 0))
    (perf-delete-scatter n)))

(perf-define-test-suite perf-marker-suite
  (perf-define-marker-test insert before)
  (perf-define-marker-test insert after)
  (perf-define-marker-test insert scatter)
  (perf-define-marker-test delete before)
  (perf-define-marker-test delete after)
  (perf-define-marker-test delete scatter))

(perf-define-variable-test perf-insert-after (n)
  (with-temp-buffer
    (perf-insert-text n)
    (perf-insert-overlays-scattered n)
    (goto-char (point-max))
    (overlay-recenter (point-max))
    (benchmark-run 1
      (dotimes (_ (/ n 2))
        (insert ?X)))))

(perf-define-variable-test perf-insert-scatter (n)
  (with-temp-buffer
    (perf-insert-text n)
    (perf-insert-overlays-scattered n)
    (goto-char (point-max))
    (benchmark-run 1
      (dotimes (_ (/ n 2))
        (goto-char (1+ (random (point-max))))
        (insert ?X)))))

(perf-define-variable-test perf-delete-before (n)
  (with-temp-buffer
    (perf-insert-text n)
    (perf-insert-overlays-scattered n)
    (goto-char 1)
    (overlay-recenter (point-min))
    (benchmark-run 1
      (dotimes (_ (/ n 2))
        (delete-char 1)))))

(perf-define-variable-test perf-delete-after (n)
  (with-temp-buffer
    (perf-insert-text n)
    (perf-insert-overlays-scattered n)
    (goto-char (point-max))
    (overlay-recenter (point-max))
    (benchmark-run 1
      (dotimes (_ (/ n 2))
        (delete-char -1)))))

(perf-define-variable-test perf-delete-scatter (n)
  (with-temp-buffer
    (perf-insert-text n)
    (perf-insert-overlays-scattered n)
    (goto-char (point-max))
    (benchmark-run 1
      (dotimes (_ (/ n 2))
        (goto-char (max 1 (random (point-max))))
        (delete-char 1)))))

(perf-define-test-suite perf-insert-delete-suite
  'perf-insert-before
  'perf-insert-after
  'perf-insert-scatter
  'perf-delete-before
  'perf-delete-after
  'perf-delete-scatter
  )

\f
;; +===================================================================================+
;; | Redisplay (new)
;; +===================================================================================+

;; 5000
;; 25000
;; 75000

;; Number of Overlays =  N / 2
;;
;; (except for the hierarchical case, where it is divided by 10.)

  ;; . scrolling through a buffer with lots of overlays that affect faces
  ;;   of characters in the buffer text
  ;; . scrolling through a buffer with lots of overlays that define
  ;;   'display' properties which are strings
  ;; . scrolling through a buffer with lots of overlays that define
  ;;   'invisible' properties

(perf-define-test-suite perf-display-suite
  (perf-define-display-test sequential display scroll)
  (perf-define-display-test sequential display random)
  (perf-define-display-test sequential face scroll)
  (perf-define-display-test sequential face random)
  (perf-define-display-test sequential invisible scroll)
  (perf-define-display-test sequential invisible random)
  (perf-define-display-test random display scroll)
  (perf-define-display-test random display random)
  (perf-define-display-test random face scroll)
  (perf-define-display-test random face random)
  (perf-define-display-test random invisible scroll)
  (perf-define-display-test random invisible random))

;; |------------|
;;   |--------|
;;     |----|
(perf-define-display-test hierarchical face scroll)



\f
;; +===================================================================================+
;; | Real World
;; +===================================================================================+

(require 'python)

(defconst perf-many-errors-file
  (expand-file-name "many-errors.py"
                    (and load-file-name (file-name-directory load-file-name))))

(perf-define-constant-test perf-realworld-flycheck
  (interactive)
  (package-initialize)
  (when (and (require 'flycheck nil t)
             (file-exists-p perf-many-errors-file)
             (or (executable-find "pylint")
                 (executable-find "flake8")))
    (setq flycheck-python-pylint-executable
          (executable-find "pylint"))
    (setq flycheck-python-flake8-executable
          (executable-find "flake8"))
    (setq python-indent-guess-indent-offset-verbose nil)
    (setq flycheck-check-syntax-automatically nil)
    (setq flycheck-checker-error-threshold nil)
    (setq flycheck-display-errors-function nil)
    (with-current-buffer (find-file-noselect perf-many-errors-file)
      (let* ((done)
             (flycheck-after-syntax-check-hook
              (list (lambda () (setq done t)))))
        (flycheck-mode 1)
        (flycheck-buffer)
        (benchmark-run 1
          (while (not done)
            (accept-process-output))
          (perf-switch-to-buffer-scroll-up-and-down)
          (flycheck-mode -1))))))

;; https://lists.gnu.org/archive/html/emacs-devel/2009-04/msg00242.html
(defun make-lines-invisible (regexp &optional arg)
  "Make all lines matching a regexp invisible and intangible.
With a prefix arg, make it visible again.  It is not necessary
that REGEXP matches the whole line; if a hit is found, the
affected line gets automatically selected.

This command affects the whole buffer."
  (interactive "MRegexp: \nP")
  (let (ov
        ovs
        count)
    (cond
     ((equal arg '(4))
      (setq ovs (overlays-in (point-min) (point-max)))
      (mapc (lambda (o)
              (if (overlay-get o 'make-lines-invisible)
                  (delete-overlay o)))
            ovs))
     (t
      (save-excursion
        (goto-char (point-min))
        (setq count 0)
        (while (re-search-forward regexp nil t)
          (setq count (1+ count))
          (if (= (% count 100) 0)
              (message "%d" count))
          (setq ov (make-overlay (line-beginning-position)
                                 (1+ (line-end-position))))
          (overlay-put ov 'make-lines-invisible t)
          (overlay-put ov 'invisible t)
          (overlay-put ov 'intangible t)
          (goto-char (line-end-position))))))))

(perf-define-constant-test perf-realworld-make-lines-invisible
  (with-temp-buffer
    (insert-file-contents "/usr/share/dict/words")
    (set-window-buffer nil (current-buffer))
    (redisplay t)
    (overlay-recenter (point-max))
    (benchmark-run 1
      (make-lines-invisible "a"))))

(perf-define-constant-test perf-realworld-line-numbering
  (interactive)
  (with-temp-buffer
    (insert-file-contents "/usr/share/dict/words")
    (overlay-recenter (point-max))
    (goto-char (point-min))
    (let* ((nlines (count-lines (point-min) (point-max)))
           (line 1)
           (width 0))
      (dotimes (i nlines) ;;-with-progress-reporter "Creating overlays"
        (let ((ov (make-overlay (point) (point)))
              (str (propertize (format "%04d" line) 'face 'shadow)))
          (overlay-put ov 'before-string
                       (propertize " " 'display `((margin left-margin) ,str)))
          (setq width (max width (length str)))
          (cl-incf line)
          (forward-line)))
      (benchmark-run 1
        (let ((left-margin-width width))
          (perf-switch-to-buffer-scroll-up-and-down))))))

(perf-define-test-suite perf-realworld-suite
  'perf-realworld-flycheck
  'perf-realworld-make-lines-invisible
  'perf-realworld-line-numbering)

\f
;; +===================================================================================+
;; | next-overlay-change
;; +===================================================================================+

(perf-define-variable-test perf-noc-hierarchical/forward/linear (n)
  "Search linear for the next change on every line."
  (with-temp-buffer
    (perf-insert-lines (* 3 n))
    (perf-insert-overlays-hierarchical n)
    (goto-char (point-min))
    (benchmark-run 1
      (while (not (eobp))
        (next-overlay-change (point))
        (forward-line)))))

(perf-define-variable-test perf-noc-sequential/forward/linear (n)
  "Search linear for the next change on every line."
  (with-temp-buffer
    (perf-insert-lines (* 3 n))
    (perf-insert-overlays-sequential n)
    (goto-char (point-min))
    (benchmark-run 1
      (while (not (eobp))
        (next-overlay-change (point))
        (forward-line)))))

(perf-define-variable-test perf-noc-hierarchical/forward/backnforth (n)
  "Search back and forth for the next change from `point-min' to `point-max'."
  (with-temp-buffer
    (perf-insert-lines (* 3 n))
    (overlay-recenter (point-max))
    (perf-insert-overlays-hierarchical n)
    (goto-char (point-min))
    (benchmark-run 1
      (while (not (eobp))
        (next-overlay-change (point))
        (next-overlay-change (+ (point) 2))
        (forward-char)))))

(perf-define-test-suite perf-noc-suite
  'perf-noc-hierarchical/forward/linear
  'perf-noc-hierarchical/forward/backnforth
  'perf-noc-hierarchical/forward/backnforth)

debug log:

solving 34cc6abd310 ...
found 34cc6abd310 in https://yhetil.org/emacs/1VzhyYQmzkY8ZudqyPNciqngpUIHE7bpzCHQJQJhmJUvyq0OSOCMOKiAOS3s7FVO67oKaW-67ZrLQhvT_4Pth1TlHl8Z9XfGEvV8WD16m0c=@pm.me/ ||
	https://yhetil.org/emacs/N0O-eiIpxKNtUY2ZEohzUF--05o8uBc2wHsLVw7KrVJbG_Lt6kzkiKaN_ZTRdPv8jIxc_yAj-2-DVrzFi6MyYHwrgxHl11h6MYvHeqz1p9E=@hypnicjerk.ai/ ||
	https://yhetil.org/emacs/obyPxjc1-gUH7aZNNaGIIzybT6m7sLarevWp3z6KXBhb4rCC9G_FzTOuPtDs2saC3vQOVoMNPO6Bn3UQFa5KvbgtbNUjefNA3ArTasTnDy4=@hypnicjerk.ai/ ||
	https://yhetil.org/emacs/2LOLmIp1X8w4CGbqq3qDrzmKVA0KzYNL1N9lBtWdB-MtEv9oCuYgJMYprG170wMPjYxeQImAmWOPatGTTl4KxZMlptNo9A9hnHt84vdN9EA=@hypnicjerk.ai/
found 56cb72fc308 in https://git.savannah.gnu.org/cgit/emacs.git
preparing index
index prepared:
100644 56cb72fc30870b227d24aa2a368968cb3950be43	test/manual/noverlay/overlay-perf.el

applying [1/1] https://yhetil.org/emacs/1VzhyYQmzkY8ZudqyPNciqngpUIHE7bpzCHQJQJhmJUvyq0OSOCMOKiAOS3s7FVO67oKaW-67ZrLQhvT_4Pth1TlHl8Z9XfGEvV8WD16m0c=@pm.me/
diff --git a/test/manual/noverlay/overlay-perf.el b/test/manual/noverlay/overlay-perf.el
index 56cb72fc308..34cc6abd310 100644

Checking patch test/manual/noverlay/overlay-perf.el...
Applied patch test/manual/noverlay/overlay-perf.el cleanly.

skipping https://yhetil.org/emacs/N0O-eiIpxKNtUY2ZEohzUF--05o8uBc2wHsLVw7KrVJbG_Lt6kzkiKaN_ZTRdPv8jIxc_yAj-2-DVrzFi6MyYHwrgxHl11h6MYvHeqz1p9E=@hypnicjerk.ai/ for 34cc6abd310
skipping https://yhetil.org/emacs/obyPxjc1-gUH7aZNNaGIIzybT6m7sLarevWp3z6KXBhb4rCC9G_FzTOuPtDs2saC3vQOVoMNPO6Bn3UQFa5KvbgtbNUjefNA3ArTasTnDy4=@hypnicjerk.ai/ for 34cc6abd310
skipping https://yhetil.org/emacs/2LOLmIp1X8w4CGbqq3qDrzmKVA0KzYNL1N9lBtWdB-MtEv9oCuYgJMYprG170wMPjYxeQImAmWOPatGTTl4KxZMlptNo9A9hnHt84vdN9EA=@hypnicjerk.ai/ for 34cc6abd310
index at:
100644 34cc6abd310bb23215d76569fd5c065f5f4ddd1a	test/manual/noverlay/overlay-perf.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.