Tk: non-default font 16 x slower

When I use the default fonts in my Ruby-Tk application it takes
400 milliseconds to start up. When I use Helvetica or other fonts it takes
6400 seconds. Is there something I can do about that? Perl does not have
that problem.

···


Wybo

Hi,

···

From: Wybo Dekker wybo@servalys.nl
Subject: Tk: non-default font 16 x slower
Date: Mon, 18 Aug 2003 19:52:35 +0900
Message-ID: Pine.LNX.4.44.0308181227580.1504-100000@servalys.nl

When I use the default fonts in my Ruby-Tk application it takes
400 milliseconds to start up. When I use Helvetica or other fonts it takes
6400 seconds. Is there something I can do about that? Perl does not have
that problem.

Could you tell me your environment ( Ruby version, Tcl/Tk version, OS,
and so on ) and send me your script?

Maybe the problem depends on auto-creation of font objects.
If you use the same font for many widgets, please create a TkFont
object for the font and try to give the font object to the font option
of each widgets.

                              Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)

Use a font explicitely, not only string references (which causes the font
to be built over and over again), like:

font = TkFont.new(‘courier’)
widget.font(font)

hth,
Kero.

···

On Mon, 18 Aug 2003 19:52:35 +0900, Wybo Dekker wrote:

When I use the default fonts in my Ruby-Tk application it takes
400 milliseconds to start up. When I use Helvetica or other fonts it takes
6400 seconds. Is there something I can do about that? Perl does not have
that problem.

Hi,

···

From: Wybo Dekker wybo@servalys.nl
Subject: Tk: non-default font 16 x slower
Date: Mon, 18 Aug 2003 19:52:35 +0900
Message-ID: Pine.LNX.4.44.0308181227580.1504-100000@servalys.nl

When I use the default fonts in my Ruby-Tk application it takes
400 milliseconds to start up. When I use Helvetica or other fonts it takes
6400 seconds. Is there something I can do about that? Perl does not have
that problem.

I improved font control of Ruby/Tk on CVS. Probably, it has better
performance at setting the font option by a font name string.

On the operation of old version, Ruby/Tk creates automatically a
TkFont object which depends on the font parameters. To create a
TkFont object, Ruby/Tk creates named fonts on the Tk interpreter.
The Tk interpreter search a font which matchs to the font parameters.
The search needs large cost.

On the operation of new version, Ruby/Tk does NOT creates
automatically a TkFont object. Only requests the Tk interpreter to
set the font of the widget to the font based on the font parameters.

However, if the font option of the widget is refered, Ruby/Tk creates
a new TkFont object for current font of the widget and replaces the
font of the widget to the TkFont object. The purpose of this operation
is to allow such like as the following method call.

b = TkButton.new(:text=>‘aaaAAAaaa’, :font=>‘courier’).pack
b.font.size(20)

Without replacing the font, b.font returns a font name string.
So, b.font.size(20) will raise an exception.

If you can, please get the newest version of Ruby/Tk from CVS and try it.

                              Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)

very good tip, but why is font creation so exceedingly slow
anyway?
On a Pentium 100 it used to take a few seconds with a font
that was already cached by xfs.

Richard

···

On Tue, Aug 19, 2003 at 05:21:58AM +0900, Kero van Gelder wrote:

On Mon, 18 Aug 2003 19:52:35 +0900, Wybo Dekker wrote:

When I use the default fonts in my Ruby-Tk application it takes
400 milliseconds to start up. When I use Helvetica or other fonts it takes
6400 seconds. Is there something I can do about that? Perl does not have
that problem.

Use a font explicitely, not only string references (which causes the font
to be built over and over again), like:

font = TkFont.new(‘courier’)

Hi,

···

From: Richard Zidlicky rz@linux-m68k.org
Subject: Re: Tk: non-default font 16 x slower
Date: Tue, 19 Aug 2003 20:40:55 +0900
Message-ID: 20030819105527.GA2197@linux-m68k.org

very good tip, but why is font creation so exceedingly slow
anyway?

Ruby/Tk recommends to distinguish between (1) widgets have the
SAME font, and (2) widgets coincidentally have the fonts with
same properties. That is the reason of creating a named font
when a font name is given to ‘font’ option. When properties of
a TkFont object are changed, displayed font images of all widgets
given the TkFont object are changed. However, it needs large cost
to create a new named font. So, Ruby/Tk is slow if you give the
‘font’ option with a font name to each of many widgets.

                              Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)

When I use the default fonts in my Ruby-Tk application it takes
400 milliseconds to start up. When I use Helvetica or other fonts it takes
6400 seconds. Is there something I can do about that? Perl does not have
that problem.

Use a font explicitely, not only string references (which causes the font
to be built over and over again), like:

font = TkFont.new(‘courier’)

very good tip, but why is font creation so exceedingly slow
anyway?
On a Pentium 100 it used to take a few seconds with a font
that was already cached by xfs.

It is “created” in Tk. Probably some “extra” things happen.
The answer to what happens, would be in some Tk manual or newsgroup :slight_smile:

Bye,
Kero.