back-button icon indicating copy to clipboard operation
back-button copied to clipboard

ucs-utils causes slow shutdown on Windows

Open jocap opened this issue 3 years ago • 3 comments

It seems that ucs-utils causes C-x C-c to take around three, four seconds on Windows 7. I have yet to figure out exactly what causes it within ucs-utils, but in the mean time, seeing as how Unicode characters aren't really essential to back-button-mode, it may be a good idea to make ucs-utils an optional dependency or to disable it when the operating system is Windows. The following change (around line 417) would fix it:

-(when (featurep 'ucs-utils)
+(when (and (featurep 'ucs-utils)
+           (not (equal system-type 'windows-nt)))
-  (setq back-button-spacer-char (ucs-utils-char back-button-index-spacer-ucs-name back-button-spacer-char 'cdp))
-  (setq back-button-thumb-char  (ucs-utils-char back-button-index-thumb-ucs-name  back-button-thumb-char  'cdp)))

As it stands, installing and enabling back-button-mode causes slow shutdowns on my Windows 7 system at least, even with -Q and even if back-button-mode is disabled again. Ideally, I'd like to find the cause in ucs-utils, but I haven't been able to do so yet.

jocap avatar Aug 27 '22 14:08 jocap

Hi!

All ucs-utils is doing is providing some cleverness/fallback about which character to display. That was made years ago when it was not at all clear that a given Unicode character could be displayed.

These days we can just assume that the character is displayable. At least in a graphical context, we can.

So yes, I agree it isn't essential to the mode, and can be changed for all cases.

The lag itself sounds like ucs-utils is regenerating a cache. Are you using Emacs 28.x? I am still on 27.x.

rolandwalker avatar Aug 27 '22 14:08 rolandwalker

Hi! Thanks for the info! Yes, I am on 28.1.

It seems then that the following could replace ucs-utils-char:

(defun back-button--char (name fallback)
  (or (if (version< emacs-version "26")
          (cdr (assoc-string name (ucs-names) t))
        (char-from-name name t))
      fallback))

If you're interested, I could submit a pull request.

jocap avatar Aug 27 '22 15:08 jocap

That would be nice. Consider whether you want to test char-displayable-p or display-graphic-p.

rolandwalker avatar Aug 27 '22 16:08 rolandwalker