Skip to content

Fix to make deft faster (also on older emacsen) #115

@xot

Description

@xot

Deft is slow when handling a lot of notes (several others have reported the issue here). After profiling, it turns out the culprit is string-width, at least on < 29.1 Emacs and Emacs 29.1 native on MacOS (for now).

Luckily, in deft, string-width is always called to test whether a string is less wide than (at most) the window width, or to truncate a string to (at most) the window width. In other words, if we first cut the string to something reasonable small (let's use 4 times the window width to account for UTF and emoji roughly) before computing the actual width, we are good. So define

(defun deft-truncate-string-to-window-width (str)
  (if str
      (if (> (length str) (* deft-window-width 4))
          (substring str 0 (* deft-window-width 4))
	  str
      )
   ""
  )
)

(defun deft-string-width (str)
  (string-width (deft-truncate-string-to-window-width str))  
)

(defun deft-truncate-string-to-width (str width)
  (truncate-string-to-width (deft-truncate-string-to-window-width str) width)  
)

And use deft-truncate-string-to-width instead of truncate-string-to-width in deft-file-widget.

(More info here)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions