Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
xot opened this issue Aug 2, 2023 · 3 comments
Open

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

xot opened this issue Aug 2, 2023 · 3 comments

Comments

@xot
Copy link

xot commented Aug 2, 2023

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)

@mdelhey
Copy link

mdelhey commented Aug 20, 2023

I'm also having the same slow-down problem. But it looks like deft-file-widget is part of an older version of deft, as far as I can tell. The current version uses deft-file-button. Any idea how to fix the problem for this?

@xot
Copy link
Author

xot commented Aug 23, 2023

Hm.. I thought 0.8 was the latest version, which uses deft-file-widget. What version are you referring to?

@mdelhey
Copy link

mdelhey commented Aug 24, 2023

Looks like "widgets" were replaced with "buttons" in this update 28be94d

The fix works if you rename the function to deft-file-button.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants