Subject: loading fonts has become **slow**

From: [email-masked]
Date: Fri, 4 Apr 2003 02:47:07 +0200

Current cvs,

  $ fvwm --version
  fvwm 2.5.7 (from cvs) compiled on Apr  4 2003 at 01:21:19
  with support for: ReadLine, RPlay, Stroke, XPM, PNG, Shape, XShm, SM, Bidi text, Xinerama, XRender, XFT, NLS

  $ locale
  LANG=POSIX
  LC_CTYPE=de_DE@euro
  ...
  LC_ALL=

Loading fonts has become very slow, because the code in Flocale.c
insists on using fontsets, eventually calling XCreateFontSet which
takes about 0.2 seconds to return (1400 MHz Athlon).  This is
extremely annoying for a transient FvwmPager.

Bye

Dominik ^_^  ^_^

 --
Dominik Vogt, [email-masked]
Reply-To: [email-masked]
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]

---

From: Olivier Chapuis <[email-masked]>
Date: Fri, 4 Apr 2003 09:00:31 +0200

> extremely annoying for a transient FvwmPager.

Yes loading default FVWM font is slow (at least with XFree-4.x x < 3).
The default FVWM font:

#define FLOCALE_MB_FALLBACK_FONT \
	"-*-fixed-medium-r-semicondensed-*-13-*," \
	"-*-fixed-medium-r-normal-*-14-*," \
	"-*-medium-r-normal-*-16-*"
/* rationale: -*-fixed-medium-r-semicondensed-*-13-* should gives "fixed" in
   most non multibyte charset (?).
   -*-fixed-medium-r-normal-*-14-* is ok for jsx
   -*-medium-r-normal-*-16-* is for gb
*/

is too general but try to handle any situation. If the patch I sent
to XFree has been well applied I hope that loading such a general font
is really faster with XFree-4.3, there is/was(?) a bug in font
matching (I only check that they apply the fix to an enormous memory
leak in XCreateFontSet).
If you specialize your font I hope that font loading is really faster:

*FvwmPager: font -misc-fixed-medium-r-semicondensed-*-13-iso8859-15

or

*FvwmPager: font fixed

No?

What we can do is to add a default font for each known locale.
Or when loading the "default" font we can first try to add
the locale charset to FLOCALE_MB_FALLBACK_FONT.

Regards, Olivier

---

From: Olivier Chapuis <[email-masked]>
Date: Mon, 7 Apr 2003 08:41:23 +0200

> extremely annoying for a transient FvwmPager.

Can you give more detail? XFree version, FvwmPager config (the
fonts config line) and the output of "PrintInfo locale".
XCreateFontSet can be slow in some situation (XFree-4.3 has
some improvement and I will try add a few workaround in FVWM)
but 0.2 seconds seems enormous.

Regards, Olivier

---

From: Olivier Chapuis <[email-masked]>
Date: Tue, 8 Apr 2003 11:18:30 +0200

On Mon, Apr 07, 2003 at 09:54:13AM +0200, Dominik Vogt wrote:
> On Fri, Apr 04, 2003 at 09:00:31AM +0200, Olivier Chapuis wrote:
> I have
>   *FvwmPagerFont none
>   *FvwmPagerSmallFont 5x7

5x7 is a bad font name :o) a better name is:
   -*-fixed-medium-r-normal--7-*-*-*-*-*-*-*
this way a user which use your config with a locale charset
!= iso8859-1 will have a font with the good locale charset.

> 
> The first call to FlocaleLoadFont in initialize_pager()
> (x_pager.c) is the one call that is slow.  I guess it's the one
> that loads the default font in place of 'none' (which seems
> useless).
> 
> In any case, I don't understand why I need a font set at all.

Using font set is useful for the following 2 reasons:

- It is the only way I know (but xft) which allows to render
correctly multibyte text.
- *And* fonts are loaded in an intelligent way: say that your
locale charset is "foo-x" and you ask the font
     -*-fixed-bold-r-*-14-*
then with fontset a font which match
     -*-fixed-medium-r-*-14-*-foo-x
will be loaded. With font struct the loaded font will depend
on your X install and the loaded font will probably match:
     -*-fixed-bold-r-*-14-*-iso8859-1
(and I want a font which match -*-fixed-bold-r-*-14-*-iso8859-15).

In fact font set is not useful in the following situation:
The font is not a multibyte font _and_ you specify the charset
in the font name.

> And
> since i18n is not an option anymore, I can't even disable it.
>

It will be very easy to disable the use of font set: Just return null
at the beginning of FlocaleGetFontSet in Flocale.c. So we may easily add
a --disable-fontset configure option. However, I am not sure this is
a great idea.
What we can do:

  1. Using: "-*-fixed-medium-r-semicondensed-*-13-*-*-*-*-*-*-*," \
           "-*-fixed-medium-r-normal-*-14-*-*-*-*-*-*-*," \
           "-*-*-medium-r-normal-*-16-*-*-*-*-*-*-*-*"
    as default font really speed-up default font loading
  2. If a font name contains the charset and it is != from the X locale
    charset use a font struct.
  3. Optional: If a font name contains the charset and it is not multibyte
    use a font struct (need a new entries in  the FlocaleCharsetTable).
    This not really needed has there is no "speed" problem here.
  Note: These 2 workarounds will not handle the case of aliased font name
        as fixed, 5x7 ...etc. Again using such name in a config file is bad,
        bad, bad! 
  4. Optional: adding a new flags in FVWM font name "nofontset" (to be put
     in the same place as encoding= and shadow=) to forbid the use of
     fontset.

I've committed 1. I will do 2. soon. If you want I can do 4. and I am
not sure that 3. is a good idea at all.

I am really surprised with your 0.2 sec pbs. XCreateFontSet can be slow
but 0.2 sec seems enormous. I will be interested to know if you still
have this 0.2 sec pbs after my "fixed the default font name" commit.
Also, can you send the output of "PrintInfo locale". Maybe your X locale
charset is iso8859-15 (which can be != from your locale charset, e.g.,
iso8859-1, this is not a pb). Then loading some iso8859-1 fonts (fixed
and 5x7 are in general iso8859-1) can be really slow. This will be
partially fixed by 2.

Regards, Olivier

PS1: It seems that I've a few mail pb, my mails arrive with some
     delays.

PS2: Here a few tests (on my new 2GHz P-IV laptop):

THE TEST: loading/unloading 100 times a font with XCreateFontSet
          The locale X charset is iso8859-15

* With the old default FVWM font:
    "-*-fixed-medium-r-semicondensed-*-13-*,\
    -*-fixed-medium-r-normal-*-14-*,-*-medium-r-normal-*-16-*"
 
   - With XFREE-4.3.0: 0.17 sec
   - With XFREE-4.2.1: 2.05 sec

  Note the big difference (thanks to me :o)

* With the new default FVWM font:
  "-*-fixed-medium-r-semicondensed-*-13-*-*-*-*-*-*-*," \
  "-*-fixed-medium-r-normal-*-14-*-*-*-*-*-*-*," \
  "-*-*-medium-r-normal-*-16-*-*-*-*-*-*-*-*"

  - With XFREE-4.3.0: 0.17 sec
  - With XFREE-4.2.1: 0.34 sec

* With -*-fixed-*-iso8859-15:

  - With XFREE-4.3.0: 0.15 sec
  - With XFREE-4.2.1: 0.15 sec

* With -*-fixed-*-iso8859-1 (no matching font!! my locale X charset
  is iso8859-15):

  - With XFREE-4.3.0: 2.63 sec
  - With XFREE-4.2.1: 6.02 sec 

This is the really bad situation. 2) will fix it.

---

From: Olivier Chapuis <[email-masked]>
Date: Thu, 10 Apr 2003 08:21:43 +0200

> extremely annoying for a transient FvwmPager.

Do you see some improvement since my last commit "Load a FontSet only when
this is reasonable"?

Regards, Olivier