Skip to content

Instantly share code, notes, and snippets.

@jdtsmith
Last active March 16, 2023 16:35
Show Gist options
  • Save jdtsmith/a87afb057761260c1207d8503f437f90 to your computer and use it in GitHub Desktop.
Save jdtsmith/a87afb057761260c1207d8503f437f90 to your computer and use it in GitHub Desktop.
undo/redo + vundo stress test
;; Stress tests of the undo/vundo system
(require 'vundo)
(require 'lorem-ipsum)
(eval-when-compile
(require 'cl-lib))
(require 'memory-report)
(add-hook 'vundo-mode-hook (lambda () (setq jit-lock-mode nil)))
(defun vundo--stress-test (&optional nedits nundos max-chain-length)
(interactive
(list (read-number "Number of edits (sentences): " 3000)
(read-number "Approximate number of undo/redo chains: " 500)
(read-number "Maximum undo length: " 14))) ;*very* sensitive to this number
(let ((obuf (get-buffer-create "*vundo-stress-test*"))
(vundo-window-max-height 30))
(with-current-buffer obuf
(read-only-mode -1)
(font-lock-mode -1)
(setq buffer-undo-list nil
pending-undo-list nil)
(erase-buffer)
(if-let ((vbuf (vundo-1 obuf)))
(kill-buffer vbuf))
(cl-loop for n upto nedits
for r = (random nedits)
do
(lorem-ipsum-insert-sentences 1)
(insert "\n")
(undo-boundary)
(when (<= r nundos)
(condition-case nil
(progn (undo (1+ (random max-chain-length)))
(undo-boundary))
(error (undo-boundary)))))
(display-buffer "*vundo-stress-test*")
(message "Undo stress test complete:\n\t%d sentences inserted\n\t%d undo chains of max length %d"
nedits nundos max-chain-length)
(message "\tundo-limits: %d strong: %d outer: %d"
undo-limit undo-strong-limit undo-outer-limit)
(message "\tbuffer-undo-list: length %7d, %9d bytes"
(length buffer-undo-list)
(memory-report-object-size buffer-undo-list))
(call-interactively #'count-words)
(message "> Launching vundo: ")
(benchmark-progn (vundo))
(message "> Navigating to tree root: ")
(setq vundo--message nil
cursor-type nil)
(benchmark-progn (while (vundo-stem-root)))
(vundo--debug)
(let ((ul (buffer-local-value 'buffer-undo-list obuf)))
(message "\tbuffer-undo-list: length %7d, %9d bytes"
(length ul) (memory-report-object-size ul))))))
@jdtsmith
Copy link
Author

Added navigation to root benchmark. Disabled jit-lock-mode in vundo-mode-hook (should probably be done by vundo).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment