Some geiser commands for profiling

Inspired by this recent article on optimization:

dthompson.us/posts/optimizing-guile-scheme.html

Here are some emacs command for sending scheme expressions to the REPL and profile them. I’ve always wondered why compilers do not provide simpler ways to assess the performance of code, Guile’s profile and disassemble commands are pretty useful for this.

(defun my/geiser-send (start end)
 "Send region to the REPL's profile command." 
  (interactive "r")
  (let ((region (buffer-substring-no-properties start end)  ))
    (geiser-repl-switch) 
    (geiser-repl--send
(format ",profile %s"
      region))))

(defun my/geiser-loop-profile (start end)
 "Send region to the REPL's profile command, the region is  enclosed in loop." 
  (interactive "r")
  (let ((region (buffer-substring-no-properties start end)  ))
    (geiser-repl-switch) 
    (geiser-repl--send
     (format  
      ",profile (let lp ((i 0))
     (when (< i 100000000)
     %s
     (lp (+ i 1))))"
      region))))

(defun my/geiser-dissasemble ()
 "Send sexp-at-point as argument to the disassemble command in the REPL." 
  (interactive )
  (let ((sexp (sexp-at-point)))
    (geiser-repl-switch) 
    (geiser-repl--send
    (format  
     ",disassemble %s"
     sexp))))
6 Likes

This is really cool, thanks for sharing it!

1 Like