Subject: Re: bug#26402: 25.2; Font rendering extremely slow on any non-default font

From: Eli Zaretskii <[email-masked]>
Date: Sat, 08 Apr 2017 20:18:15 +0300

[Please keep the bug address on the CC list.]

> From: Gennady Uraltsev <[email-masked]>
> Date: Sat, 8 Apr 2017 18:32:34 +0200
> 
> The default font that emacs -Q starts with is
> 
> xft:-adobe-Source Code
> Pro-normal-normal-normal-*-15-*-*-*-m-0-iso10646-1 (#x2C)
> 
> (I guess it comes from the fact that that is my predefined qt and gtk
> monospace font)
> 
> once zooming in (text-scale-adjust INC) I get
> 
> xft:-adobe-Source Code
> Pro-normal-normal-normal-*-18-*-*-*-m-0-iso10646-1 (#x1E)
> 
> If instead of zooming in I do M-x buffer-face-set variable-pitch
> I get the font
> 
>   xft:-unknown-Roboto-normal-normal-normal-*-15-*-*-*-*-0-iso10646-1 (#x48)
> 
> 
> 
> I can also replicate this by setting the global font to be something
> else like
> 
> xft:-unknown-Droid Sans-normal-normal-normal-*-15-*-*-*-*-0-iso10646-1
> (#x54)
> xft:-monotype-Noto Sans-normal-normal-normal-*-15-*-*-*-*-0-iso10646-1
> (#x36)
> 
> at the level of the frame by using
> 
> M-x set-frame-font
> -unknown-Droid Sans-normal-normal-normal-*-*-*-*-*-*-0-iso10646-1
> or
> -monotype-Noto Sans-normal-normal-normal-*-*-*-*-*-*-0-iso10646-1
> 
> respectively. This does not have a negative impact on performance. But
> as soon as I enable  something like
> 
> M-x buffer-face-set fixed-pitch or
> (text-scale-adjust INC) the problem returns

Can you build your own Emacs?  If so, could you please apply the
following patch and see if it solves the problem?

diff --git a/src/font.c b/src/font.c
index a929509..bb6d18b 100644
--- a/src/font.c
+++ b/src/font.c
@@ -2777,21 +2777,22 @@ font_list_entities (struct frame *f, Lisp_Object spec)
 	  val = XCDR (val);
 	else
 	  {
-	    val = driver_list->driver->list (f, scratch_font_spec);
-	    if (!NILP (val))
-	      {
-		Lisp_Object copy = copy_font_spec (scratch_font_spec);
+	    Lisp_Object copy;
 
-		val = Fvconcat (1, &val);
-		ASET (copy, FONT_TYPE_INDEX, driver_list->driver->type);
-		XSETCDR (cache, Fcons (Fcons (copy, val), XCDR (cache)));
-	      }
+	    val = driver_list->driver->list (f, scratch_font_spec);
+	    if (NILP (val))
+	      val = zero_vector;
+	    else
+	      val = Fvconcat (1, &val);
+	    copy = copy_font_spec (scratch_font_spec);
+	    ASET (copy, FONT_TYPE_INDEX, driver_list->driver->type);
+	    XSETCDR (cache, Fcons (Fcons (copy, val), XCDR (cache)));
 	  }
-	if (VECTORP (val) && ASIZE (val) > 0
+	if (ASIZE (val) > 0
 	    && (need_filtering
 		|| ! NILP (Vface_ignored_fonts)))
 	  val = font_delete_unmatched (val, need_filtering ? spec : Qnil, size);
-	if (VECTORP (val) && ASIZE (val) > 0)
+	if (ASIZE (val) > 0)
 	  list = Fcons (val, list);
       }