From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dmitry Antipov Newsgroups: gmane.emacs.bugs Subject: bug#15876: 24.3.50; Highly degraded performance between rev 114715 and 115006 Date: Wed, 11 Dec 2013 10:52:24 +0400 Message-ID: <52A80BA8.3050403@yandex.ru> References: <867gcdiqji.fsf@somewhere.org> <86fvr09z55.fsf@somewhere.org> <83fvr01du4.fsf@gnu.org> <8638n0nj9p.fsf@somewhere.org> <86bo1eaelv.fsf@somewhere.org> <86r4a2vqbu.fsf@somewhere.org> <867gbqdisp.fsf@somewhere.org> <83haas5y88.fsf@gnu.org> <529C64C5.2040509@yandex.ru> <834n6r5edh.fsf@gnu.org> <529DAAED.9000504@yandex.ru> <83ob4y3wi5.fsf@gnu.org> <529DF416.7070807@yandex.ru> <83txeo33ls.fsf@gnu.org> <52A01D59.7030304@yandex.ru> <83lhzz2oal.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------090800020005090804040203" X-Trace: ger.gmane.org 1386744860 4419 80.91.229.3 (11 Dec 2013 06:54:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 11 Dec 2013 06:54:20 +0000 (UTC) Cc: sva-news@mygooglest.com To: Eli Zaretskii , 15876@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Dec 11 07:54:20 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Vqdga-0001T5-A7 for geb-bug-gnu-emacs@m.gmane.org; Wed, 11 Dec 2013 07:54:20 +0100 Original-Received: from localhost ([::1]:53343 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VqdgZ-0000E5-Ur for geb-bug-gnu-emacs@m.gmane.org; Wed, 11 Dec 2013 01:54:19 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60032) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VqdgP-0008Ug-Mi for bug-gnu-emacs@gnu.org; Wed, 11 Dec 2013 01:54:16 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VqdgI-0005lz-MG for bug-gnu-emacs@gnu.org; Wed, 11 Dec 2013 01:54:09 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:56901) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VqdgI-0005lu-J9 for bug-gnu-emacs@gnu.org; Wed, 11 Dec 2013 01:54:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1VqdgH-0001ud-UZ for bug-gnu-emacs@gnu.org; Wed, 11 Dec 2013 01:54:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Antipov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 11 Dec 2013 06:54:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 15876 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 15876-submit@debbugs.gnu.org id=B15876.13867448057297 (code B ref 15876); Wed, 11 Dec 2013 06:54:01 +0000 Original-Received: (at 15876) by debbugs.gnu.org; 11 Dec 2013 06:53:25 +0000 Original-Received: from localhost ([127.0.0.1]:42685 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Vqdfg-0001tc-7E for submit@debbugs.gnu.org; Wed, 11 Dec 2013 01:53:25 -0500 Original-Received: from forward20.mail.yandex.net ([95.108.253.145]:42045) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Vqdfb-0001tQ-2R for 15876@debbugs.gnu.org; Wed, 11 Dec 2013 01:53:21 -0500 Original-Received: from smtp16.mail.yandex.net (smtp16.mail.yandex.net [95.108.252.16]) by forward20.mail.yandex.net (Yandex) with ESMTP id 2CFBB1041DCB; Wed, 11 Dec 2013 10:52:29 +0400 (MSK) Original-Received: from smtp16.mail.yandex.net (localhost [127.0.0.1]) by smtp16.mail.yandex.net (Yandex) with ESMTP id D036A6A04C3; Wed, 11 Dec 2013 10:52:27 +0400 (MSK) Original-Received: from unknown (unknown [37.139.80.10]) by smtp16.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id qV4sXjNZAn-qRBaYQEM; Wed, 11 Dec 2013 10:52:27 +0400 (using TLSv1 with cipher CAMELLIA256-SHA (256/256 bits)) (Client certificate not present) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1386744747; bh=FrA2wiXpXuX/aKj4xsdRPvb+K0anACSURSkgM82U27Y=; h=Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject: References:In-Reply-To:Content-Type; b=B05bkZ0gSINQw9hJM/qThAacnNs6Dw7mPjOJjdkqNJG9yN7wcUhtvUuwG/+ZXUTBr k9fIfMAwXthoysY6GcQEgsddlSvUKU9XdoQVilEEvCAd0poU9FWP+HcgNHk18knifO O53S6g6NZ5UjyE1R6cD4al0TC8JL9c91kpoEESQQ= Authentication-Results: smtp16.mail.yandex.net; dkim=pass header.i=@yandex.ru User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 In-Reply-To: <83lhzz2oal.fsf@gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:81746 Archived-At: This is a multi-part message in MIME format. --------------090800020005090804040203 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 12/05/2013 09:36 PM, Eli Zaretskii wrote: > Yes, I see the same on Windows. However, I'm not sure we are looking > at objects we should be looking at. The ones your code traces are > font objects. By contrast, the entries in the font caches are cons > cells like this: > > (font-spec . [font-entity1 font-entity2 ...]) > > IOW, I think we should be tracing font-specs and font-entities, not > font objects. IMO the real problem is that redisplay sometimes isn't clever enough about requesting font for the particular character (0x25b7 in our case): #0 font_make_entity () at ../../trunk/src/font.c:169 #1 0x00000000005a8a3f in xfont_list_pattern (display=display@entry=0x1379260, pattern=pattern@entry=0x7fffffff7730 "-adobe-courier-*-*-*--*-*-*-*-*-*-iso10646-1", registry=registry@entry=12260082, script=script@entry=12084946) at ../../trunk/src/xfont.c:403 #2 0x00000000005a9059 in xfont_list (f=, spec=12183525) at ../../trunk/src/xfont.c:515 #3 0x0000000000563193 in font_list_entities (f=f@entry=0x111fd58, spec=spec@entry=15986301) at ../../trunk/src/font.c:2735 #4 0x0000000000563b42 in font_find_for_lface (f=f@entry=0x111fd58, attrs=attrs@entry=0x16b9510, spec=, c=c@entry=9655) at ../../trunk/src/font.c:3206 #5 0x00000000005a9d44 in fontset_find_font (fontset=18338269, c=c@entry=9655, face=face@entry=0x16b9510, id=id@entry=-1, fallback=fallback@entry=false) at ../../trunk/src/fontset.c:681 #6 0x00000000005aa210 in fontset_font (fontset=fontset@entry=17988749, c=c@entry=9655, face=face@entry=0x16b9510, id=-1) at ../../trunk/src/fontset.c:754 #7 0x00000000005aacb2 in face_for_char (f=0x111fd58, face=face@entry=0x16b9510, c=9655, pos=, object=) at ../../trunk/src/fontset.c:978 #8 0x000000000043cb45 in get_next_display_element (it=it@entry=0x7fffffff97f0) at ../../trunk/src/xdisp.c:6997 #9 0x0000000000441bc3 in display_line (it=it@entry=0x7fffffff97f0) at ../../trunk/src/xdisp.c:19593 #10 0x000000000044506a in try_window (window=window@entry=17964077, pos=..., flags=flags@entry=1) at ../../trunk/src/xdisp.c:16505 #11 0x000000000045ab57 in redisplay_window (window=17964077, just_this_one_p=just_this_one_p@entry=false) at ../../trunk/src/xdisp.c:16022 #12 0x000000000045cbf3 in redisplay_window_0 (window=window@entry=17964077) at ../../trunk/src/xdisp.c:14023 #13 0x000000000054d216 in internal_condition_case_1 (bfun=bfun@entry=0x45cbc0 , arg=17964077, handlers=, hfun=hfun@entry=0x4290a0 ) at ../../trunk/src/eval.c:1368 #14 0x000000000042d8ce in redisplay_windows (window=17964077) at ../../trunk/src/xdisp.c:14003 #15 0x000000000044a121 in redisplay_internal () at ../../trunk/src/xdisp.c:13602 Such a request produces a lot of font-entity objects, which are not needed (and becomes reachable only via font cache) after the "best match" font is selected for the particular character. Next, if font loading is too memory-intensive and gc_cons_threshold was hit, GC clears font cache. Next cursor movement triggers redisplay, which in turn asks for the "best match" for 0x25b7 again. If font cache is never cleared, this is acceptable because all possible matches (represented as a vector of font-entities) are cached. But, if font cache is cleared, font_list_entities calls to driver->list function, which creates a lot of font-entities again, etc., etc. Until we have somewhat smarter redisplay, possible solution is to clear font cache when it becomes larger than some specified size rather than at each GC. Now I have the virtual machine with Windows 7 installed, and this fix looks reasonable for me. Could you also please try it? Dmitry --------------090800020005090804040203 Content-Type: text/x-patch; name="font_cache_size_bug15876.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="font_cache_size_bug15876.patch" === modified file 'src/alloc.c' --- src/alloc.c 2013-12-09 08:23:01 +0000 +++ src/alloc.c 2013-12-11 05:38:41 +0000 @@ -5299,17 +5299,22 @@ #ifdef HAVE_WINDOW_SYSTEM +/* Rather arbitrary but willing to fix Bug#15876. */ + +#define FONT_CACHE_THRESHOLD 4096 + /* Remove unmarked font-spec and font-entity objects from ENTRY, which is (DRIVER-TYPE NUM-FRAMES FONT-CACHE-DATA ...), and return changed entry. */ static Lisp_Object -compact_font_cache_entry (Lisp_Object entry) +compact_font_cache_entry (struct terminal *t, Lisp_Object entry) { Lisp_Object tail, *prev = &entry; for (tail = entry; CONSP (tail); tail = XCDR (tail)) { bool drop = 0; + ptrdiff_t size = 0; Lisp_Object obj = XCAR (tail); /* Consider OBJ if it is (font-spec . [font-entity font-entity ...]). */ @@ -5317,8 +5322,9 @@ && !VECTOR_MARKED_P (XFONT_SPEC (XCAR (obj))) && VECTORP (XCDR (obj))) { - ptrdiff_t i, size = ASIZE (XCDR (obj)) & ~ARRAY_MARK_FLAG; + ptrdiff_t i; + size = ASIZE (XCDR (obj)) & ~ARRAY_MARK_FLAG; /* If font-spec is not marked, most likely all font-entities are not marked too. But we must be sure that nothing is marked within OBJ before we really drop it. */ @@ -5330,7 +5336,11 @@ drop = 1; } if (drop) - *prev = XCDR (tail); + { + *prev = XCDR (tail); + /* Count font-spec and vector of font-entities. */ + FONT_CACHE_SIZE (t) -= (size + 1); + } else prev = xcdr_addr (tail); } @@ -5351,10 +5361,20 @@ if (CONSP (cache)) { - Lisp_Object entry; + eassert (FONT_CACHE_SIZE (t) >= 0); + if (FONT_CACHE_SIZE (t) > FONT_CACHE_THRESHOLD) + { + Lisp_Object entry; - for (entry = XCDR (cache); CONSP (entry); entry = XCDR (entry)) - XSETCAR (entry, compact_font_cache_entry (XCAR (entry))); + fprintf (stderr, "GC%ld: font cache compaction %ld -> ", + gcs_done, FONT_CACHE_SIZE (t)); + for (entry = XCDR (cache); CONSP (entry); entry = XCDR (entry)) + XSETCAR (entry, compact_font_cache_entry (t, XCAR (entry))); + fprintf (stderr, "%ld\n", FONT_CACHE_SIZE (t)); + } + else + fprintf (stderr, "GC%ld: font cache too small (%d <= %d)\n", + gcs_done, FONT_CACHE_SIZE (t), FONT_CACHE_THRESHOLD); } mark_object (cache); } === modified file 'src/font.c' --- src/font.c 2013-12-10 03:36:36 +0000 +++ src/font.c 2013-12-11 05:35:25 +0000 @@ -2740,6 +2740,8 @@ copy = copy_font_spec (scratch_font_spec); ASET (copy, FONT_TYPE_INDEX, driver_list->driver->type); XSETCDR (cache, Fcons (Fcons (copy, val), XCDR (cache))); + /* Count font-spec and a vector of font-entities. */ + FONT_CACHE_SIZE (f->terminal) += ASIZE (val) + 1; } if (ASIZE (val) > 0 && (need_filtering @@ -2793,6 +2795,8 @@ copy = copy_font_spec (work); ASET (copy, FONT_TYPE_INDEX, driver_list->driver->type); XSETCDR (cache, Fcons (Fcons (copy, entity), XCDR (cache))); + /* Count font-spec and entity. */ + FONT_CACHE_SIZE (f->terminal) += 2; } if (! NILP (entity)) break; === modified file 'src/nsterm.h' --- src/nsterm.h 2013-12-07 16:48:12 +0000 +++ src/nsterm.h 2013-12-11 05:35:25 +0000 @@ -560,6 +560,9 @@ /* This is a cons cell of the form (NAME . FONT-LIST-CACHE). */ Lisp_Object name_list_element; + /* Amount of font-entities and font-specs objects in the cache above. */ + ptrdiff_t font_cache_size; + /* The number of fonts loaded. */ int n_fonts; === modified file 'src/termhooks.h' --- src/termhooks.h 2013-10-18 12:57:44 +0000 +++ src/termhooks.h 2013-12-11 05:35:25 +0000 @@ -628,12 +628,15 @@ #if defined (HAVE_X_WINDOWS) #define TERMINAL_FONT_CACHE(t) \ (t->type == output_x_window ? t->display_info.x->name_list_element : Qnil) +#define FONT_CACHE_SIZE(t) (t)->display_info.x->font_cache_size #elif defined (HAVE_NTGUI) #define TERMINAL_FONT_CACHE(t) \ (t->type == output_w32 ? t->display_info.w32->name_list_element : Qnil) +#define FONT_CACHE_SIZE(t) (t)->display_info.w32->font_cache_size #elif defined (HAVE_NS) #define TERMINAL_FONT_CACHE(t) \ (t->type == output_ns ? t->display_info.ns->name_list_element : Qnil) +#define FONT_CACHE_SIZE(t) (t)->display_info.ns->font_cache_size #endif extern struct terminal *get_terminal (Lisp_Object terminal, bool); === modified file 'src/w32term.h' --- src/w32term.h 2013-12-02 13:35:53 +0000 +++ src/w32term.h 2013-12-11 05:35:25 +0000 @@ -74,6 +74,9 @@ /* This is a cons cell of the form (NAME . FONT-LIST-CACHE). */ Lisp_Object name_list_element; + /* Amount of font-entities and font-specs objects in the cache above. */ + ptrdiff_t font_cache_size; + /* Number of frames that are on this display. */ int reference_count; === modified file 'src/xterm.h' --- src/xterm.h 2013-12-07 23:04:10 +0000 +++ src/xterm.h 2013-12-11 05:35:25 +0000 @@ -140,6 +140,9 @@ /* This is a cons cell of the form (NAME . FONT-LIST-CACHE). */ Lisp_Object name_list_element; + /* Amount of font-entities and font-specs objects in the cache above. */ + ptrdiff_t font_cache_size; + /* Number of frames that are on this display. */ int reference_count; --------------090800020005090804040203--