You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Display.text_pixel and Display.text_grid laggy with non-default font. #600
When drawing text to the display, each Display.text_*() call with a font string specified takes nearly 0.5 seconds to execute. This is problematic for programs that want to use the screen for status updates, while time sensitive actions are happening, such as driving while watching for a color sensor value to change, or a button to be pressed, etc.
I was able to trace the lag to the loading of the font file. I hacked a local change that directly uses the ImageDraw object methods to load the font once, and use it directly when calling the ImageDraw.text() method. This eliminated the large lag.
I don't have time right now to create a pull request with a proposed change, but wanted to document this in case anyone else sees the lag. I would also like to know if the authors are willing to consider a change that would allow a "current" font to be loaded and cached as part of the Display() object so that the Display.text_*() calls can still be used? Or maybe, there is a different mechanism that would fit better with your overall design?
Thanks for reporting! We'd definitely be interested in such a change (at least, for the v2.0 series). If there's an API change that would make this better we can consider it; the v2.0 is still labelled as beta but the next release probably won't be, so if we're going to make breaking changes we should do it now. Alternately, is this a reasonable place for some caching logic? Perhaps a table of recently used fonts?
I'll have to take a look at the APIs here and see how it works. I recall some of our APIs for the display could accept a pre-loaded font object — is that true here?
I like this strategy. I created a pull request with the change implemented. I tested it with a font string and with a preloaded font and obtained the expected behavior.
Activity
WasabiFan commentedon Mar 20, 2019
Thanks for reporting! We'd definitely be interested in such a change (at least, for the v2.0 series). If there's an API change that would make this better we can consider it; the v2.0 is still labelled as beta but the next release probably won't be, so if we're going to make breaking changes we should do it now. Alternately, is this a reasonable place for some caching logic? Perhaps a table of recently used fonts?
I'll have to take a look at the APIs here and see how it works. I recall some of our APIs for the display could accept a pre-loaded font object — is that true here?
ddemidov commentedon Mar 20, 2019
I think it would be enough to add check for
isinstance(font, str)here:ev3dev-lang-python/ev3dev2/display.py
Lines 383 to 387 in e9a1598
and only use
fonts.load()if that is the case. Something like:Then users could pass preloaded fonts into the function.
fractal13 commentedon Mar 20, 2019
I like this strategy. I created a pull request with the change implemented. I tested it with a font string and with a preloaded font and obtained the expected behavior.