After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 309322 - Font memory optimisation
Font memory optimisation
Status: RESOLVED WONTFIX
Product: vte
Classification: Core
Component: general
unspecified
Other Linux
: High normal
: ---
Assigned To: VTE Maintainers
VTE Maintainers
: 138374 332580 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2005-07-02 01:10 UTC by Mike Hearn
Modified: 2007-06-27 20:07 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
vte memory optimisation patch (967 bytes, patch)
2005-07-02 01:11 UTC, Mike Hearn
none Details | Review
Changes the above patch to use VTE_DEBUG infrastructure to be more in line with vte source code (802 bytes, patch)
2005-07-02 16:47 UTC, Michele Baldessari
none Details | Review
Patch without any debug spews (675 bytes, patch)
2005-07-02 19:11 UTC, Michele Baldessari
none Details | Review
Full backtrace (25.31 KB, text/plain)
2005-07-02 21:01 UTC, Michele Baldessari
  Details
Here is the file that gives the segfault (1.85 KB, application/octet-stream)
2005-07-02 21:02 UTC, Michele Baldessari
  Details
this one doesn't crash with the given text file nor with copy/pasted chinese characters (1.42 KB, patch)
2005-07-02 22:45 UTC, Mike Hearn
rejected Details | Review
new patch (2.32 KB, patch)
2006-04-03 17:55 UTC, Aivars Kalvans
rejected Details | Review

Description Mike Hearn 2005-07-02 01:10:05 UTC
Hi,

This patch reduces memory per tab by about 600kb/tab (I think). It works by
releasing XftFont objects as soon as it's determined they aren't needed, rather
than putting them all into the font->fonts list and waiting until exit time to
free them.

Here are some massif graphs:

Before: http://plan99.net/~mike/files/massif.31285.ps
After:  http://plan99.net/~mike/files/massif.31146.ps

I am about 90% sure this patch is correct, but it needs review by somebody who
knows VTE internals.

thanks -mike
Comment 1 Mike Hearn 2005-07-02 01:11:01 UTC
Created attachment 48529 [details] [review]
vte memory optimisation patch
Comment 2 Michele Baldessari 2005-07-02 16:45:44 UTC
Hi Mike,

I've applied this patch locally and I'll keep using it. (Seems to work fine here).
I attach a slightly changed one that uses the VTE_DEBUG infrastructure for
the debug stuff.

(So you'll need to recompile vte with --enable-debugging and export
VTE_DEBUG_FLAGS=misc to see them)

Comment 3 Michele Baldessari 2005-07-02 16:47:00 UTC
Created attachment 48556 [details] [review]
Changes the above patch to use VTE_DEBUG infrastructure to be more in line with vte source code
Comment 4 Mike Hearn 2005-07-02 17:53:11 UTC
Oh whoops, actually the printf could just be deleted, I thought I had got rid of
it but clearly not. There's no real reason to have any debug logging there.
Comment 5 Michele Baldessari 2005-07-02 19:11:36 UTC
Created attachment 48566 [details] [review]
Patch without any debug spews
Comment 6 Michele Baldessari 2005-07-02 19:13:27 UTC
*** Bug 138374 has been marked as a duplicate of this bug. ***
Comment 7 Michele Baldessari 2005-07-02 20:57:37 UTC
I think this one causes a regression as is. I applied this to my tree locally,
and when
doing a cat on a file which has some odd characters (i.e. unrecognized sequences
in particular. I'll attach the file to this bug) I get a segfault:

Program received signal SIGSEGV, Segmentation fault.
0x00173eed in FcPatternPosition (p=0x0, object=0x85ff9a0 "file") at fcpat.c:596
596         high = p->num - 1;
  • #0 FcPatternPosition
    at fcpat.c line 596
  • #1 FcPatternFindElt
    at fcpat.c line 618
  • #2 FcPatternGet
    at fcpat.c line 950
  • #3 FcPatternGetString
    at fcpat.c line 1015
  • #4 XftFontInfoFill
    at xftfreetype.c line 397
  • #5 XftFontOpenPattern
    at xftfreetype.c line 1012
  • #6 _vte_xft_font_for_char
    at vtexft.c line 243
  • #7 _vte_xft_draw_text
    at vtexft.c line 699
  • #8 _vte_draw_text
    at vtedraw.c line 274
  • #9 vte_terminal_draw_cells
    at vte.c line 13296
  • #10 vte_terminal_draw_row
    at vte.c line 13793
  • #11 vte_terminal_paint
    at vte.c line 13884
  • #12 vte_terminal_expose
    at vte.c line 14106
  • #13 _gtk_marshal_BOOLEAN__BOXED
    at gtkmarshalers.c line 83
  • #14 g_type_class_meta_marshal
    at gclosure.c line 514
  • #15 IA__g_closure_invoke
    at gclosure.c line 437
  • #16 signal_emit_unlocked_R
    at gsignal.c line 2526
  • #17 IA__g_signal_emit_valist
    at gsignal.c line 2257
  • #18 IA__g_signal_emit
    at gsignal.c line 2291
  • #19 gtk_widget_event_internal
    at gtkwidget.c line 3734
  • #20 IA__gtk_widget_send_expose
    at gtkwidget.c line 3571
  • #21 IA__gtk_main_do_event
    at gtkmain.c line 1353
  • #22 gdk_window_process_updates_internal
    at gdkwindow.c line 2218
  • #23 IA__gdk_window_process_all_updates
    at gdkwindow.c line 2271
  • #24 gdk_window_update_idle
    at gdkwindow.c line 2139
  • #25 g_idle_dispatch
    at gmain.c line 3812
  • #26 g_main_dispatch
    at gmain.c line 1933
  • #27 IA__g_main_context_dispatch
    at gmain.c line 2483
  • #28 g_main_context_iterate
    at gmain.c line 2564
  • #29 IA__g_main_loop_run
    at gmain.c line 2768
  • #30 IA__gtk_main
    at gtkmain.c line 974
  • #31 main
    at vteapp.c line 792

In this case I used the vte app inside vte/src. I'll attach the full bt.
Basically we end up setting NULL on a *patternp and then later retrieve it and
later use XftFontOpenPattern on it which gives us the crash.
Comment 8 Michele Baldessari 2005-07-02 21:01:37 UTC
Created attachment 48569 [details]
Full backtrace
Comment 9 Michele Baldessari 2005-07-02 21:02:32 UTC
Created attachment 48570 [details]
Here is the file that gives the segfault
Comment 10 Mike Hearn 2005-07-02 22:44:19 UTC
Whoops. Try this patch instead, I think I understand what VTE is doing a bit
better now. It's not really obvious that the fonts array is index linked to the
patterns array.
Comment 11 Mike Hearn 2005-07-02 22:45:28 UTC
Created attachment 48574 [details] [review]
this one doesn't crash with the given text file nor with copy/pasted chinese characters
Comment 12 Michele Baldessari 2005-07-04 19:01:56 UTC
Hi Mike,

I've applied this one to my local tree and have been using it all day for two days
now, without any problems.
Comment 13 Kjartan Maraas 2005-09-16 20:15:05 UTC
Commited. Thanks for your patience :-)
Comment 14 Behdad Esfahbod 2006-02-25 23:01:25 UTC
This patch doesn't make any sense, and breaks all font fallback.
Reverting...
Comment 15 Behdad Esfahbod 2006-02-25 23:02:01 UTC
*** Bug 332580 has been marked as a duplicate of this bug. ***
Comment 16 Behdad Esfahbod 2006-02-25 23:17:43 UTC
Lemme elaborate why this change is not correct.  It's closing fonts and putting them in the cache.  Oops.

Just reverting it seems like the best solution at this point to me.

We can somehow manage to remember that we have closed this font, so it should be reopened before next use, but that means that we may open/close multiple fonts for every new (say Chinese) character we encounter...  Can be disastrous...
Comment 17 Behdad Esfahbod 2006-02-25 23:20:34 UTC
2006-02-25  Behdad Esfahbod  <behdad@gnome.org>

        * src/vtexft.c: (_vte_xft_font_for_char): Rever the patch to
        optimize memory usage by releasing fonts that aren't needed early.
        Because that was inserting destroyed fonts into cache. Closes bug
        #332580 and reverts bug #309322.

Comment 18 Mike Hearn 2006-02-26 13:31:15 UTC
I'm sure you're correct, as I am not all that familiar with VTE or the Gnome fonts infrastructure, but from looking at the patch I don't see where a destroyed font is inserted into the cache. The code does:

loop {

ftfont = (load font)
if the character exists in the font,
   add to font->fonts   [is this the cache you mean?]
   break from loop

otherwise
close the font, ftfont = null

}

add NULL to font->fonts to keep alignment correct. The code seemed able to handle this NULL in the array just fine.


I did test the patch with some chinese text, and didn't see any obvious thrashing. But it clearly does cause a rendering regression and I'd love to know why ...
Comment 19 Mike Hearn 2006-02-26 13:33:55 UTC
Uh, the close brace was in the wrong position there. Actually the code in the patch is clear enough. Given the small changes, the only possibility I can see is either inserting NULL (which is just skipped) or inserting an opened font.
Comment 20 Behdad Esfahbod 2006-02-26 18:24:35 UTC
Yes, the cache is able to handle NULL's, but closing the font and inserting NULL means that this font will never be used in the future.  It's like the font is not there...
Comment 21 Aivars Kalvans 2006-04-03 17:55:39 UTC
Created attachment 62681 [details] [review]
new patch

I used vte with this patch for a while and it kept only 3 fonts open, not 10 like before. I also fixed a small bug: character from newly open font was not added to fontmap, it is now.
Comment 22 Behdad Esfahbod 2006-04-04 01:16:13 UTC
No, No, No.

With your patch, a font will be opened and closed again and again...  That's quite unacceptable for example when you have a lot of fonts and say cat a Chinese file that may involved thousands of different characters that you don't have any font covering...

And you fist have got to show that there's something wrong with keeping fonts open.  The original plots linked in the bug report are not available anymore.
Comment 23 Christian Kirbach 2007-06-26 18:47:20 UTC
any news here?
Comment 24 Behdad Esfahbod 2007-06-27 20:07:52 UTC
What kind of news are you looking for?  It's marked WONTFIX.