From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#31138: Native json slower than json.el Date: Mon, 25 Mar 2019 18:42:07 +0200 Message-ID: <83tvfqnbxc.fsf@gnu.org> References: <87sh806xwa.fsf@chapu.is> <834lkf7ely.fsf@gnu.org> <878t9own1p.fsf@chapu.is> <838t9o4hvl.fsf@gnu.org> <83r2ayovkx.fsf@gnu.org> <83pnqiormy.fsf@gnu.org> <83lg15pvzr.fsf@gnu.org> <83k1gppu73.fsf@gnu.org> <83ftrdprmj.fsf@gnu.org> <83d0mhpn99.fsf@gnu.org> <83zhplo25s.fsf@gnu.org> <83va09nwg3.fsf@gnu.org> <83tvftne0j.fsf@gnu.org> <40DA9396-044E-4D00-946E-42B776B51BFA@gnu.org> <83r2awnw0w.fsf@gnu.org> <83d0mgnn31.fsf@gnu.org> <835zs7och6.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="228921"; mail-complaints-to="usenet@blaine.gmane.org" Cc: sebastien@chapu.is, 31138@debbugs.gnu.org To: yyoncho Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Mar 25 17:45:09 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h8Sih-000xR9-HD for geb-bug-gnu-emacs@m.gmane.org; Mon, 25 Mar 2019 17:45:07 +0100 Original-Received: from localhost ([127.0.0.1]:45497 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h8Sif-0001cm-Ab for geb-bug-gnu-emacs@m.gmane.org; Mon, 25 Mar 2019 12:45:06 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:44763) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h8Sgi-0000Hb-1S for bug-gnu-emacs@gnu.org; Mon, 25 Mar 2019 12:43:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h8Sgg-0007uA-Nf for bug-gnu-emacs@gnu.org; Mon, 25 Mar 2019 12:43:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:45039) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h8Sgg-0007u2-Gi for bug-gnu-emacs@gnu.org; Mon, 25 Mar 2019 12:43:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1h8Sgg-0003cC-DA for bug-gnu-emacs@gnu.org; Mon, 25 Mar 2019 12:43:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 25 Mar 2019 16:43:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 31138 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: moreinfo Original-Received: via spool by 31138-submit@debbugs.gnu.org id=B31138.155353213513823 (code B ref 31138); Mon, 25 Mar 2019 16:43:02 +0000 Original-Received: (at 31138) by debbugs.gnu.org; 25 Mar 2019 16:42:15 +0000 Original-Received: from localhost ([127.0.0.1]:58580 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1h8Sfu-0003at-Pk for submit@debbugs.gnu.org; Mon, 25 Mar 2019 12:42:15 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:58391) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1h8Sfr-0003ad-Rf for 31138@debbugs.gnu.org; Mon, 25 Mar 2019 12:42:13 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:38920) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h8Sfm-0007Ru-AH; Mon, 25 Mar 2019 12:42:06 -0400 Original-Received: from [176.228.60.248] (port=3142 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1h8Sfk-0000JU-ME; Mon, 25 Mar 2019 12:42:05 -0400 In-reply-to: (message from yyoncho on Mon, 25 Mar 2019 07:44:00 +0200) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.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" Xref: news.gmane.org gmane.emacs.bugs:156765 Archived-At: > From: yyoncho > Date: Mon, 25 Mar 2019 07:44:00 +0200 > Cc: Sébastien Chapuis , > 31138@debbugs.gnu.org > > Is this with or without the patch I sent? > > It is with the patch (in the two profiler.el reports, the "kill" hooks are not present) OK, thanks. > Just found that it is not my setup which triggers the issue bug pressing C-g during the parsing: Right, I think I see the reason for that. The patch below should fix this. It also makes buffer-list-update-hook nil when creating and killing the conversion buffer, for a good measure. Please note that the patch is relative to the current master, so be sure to run "git checkout src/coding.c" before applying. > I did exactly what you are saying here: I applied the patch and listed the effects: > 1. The buffer-list-update-hook is called > 2. The patch does not affect the perf difference between emacs -q and my setup. > > > I must rely on you in this matter, because I cannot reproduce the > > slowdown on my system. > > I realize that and I am trying to be as helpful as possible by sharing all my observations. OK, but please always say if your observations are before or after the last patch I sent. Thanks. Here's the patch: diff --git a/src/coding.c b/src/coding.c index 905c7ce..c6d9643 100644 --- a/src/coding.c +++ b/src/coding.c @@ -7798,42 +7798,6 @@ static Lisp_Object Vcode_conversion_reused_workbuf; static bool reused_workbuf_in_use; -/* Return a working buffer of code conversion. MULTIBYTE specifies the - multibyteness of returning buffer. */ - -static Lisp_Object -make_conversion_work_buffer (bool multibyte) -{ - Lisp_Object name, workbuf; - struct buffer *current; - - if (reused_workbuf_in_use) - { - name = Fgenerate_new_buffer_name (Vcode_conversion_workbuf_name, Qnil); - workbuf = Fget_buffer_create (name); - } - else - { - reused_workbuf_in_use = 1; - if (NILP (Fbuffer_live_p (Vcode_conversion_reused_workbuf))) - Vcode_conversion_reused_workbuf - = Fget_buffer_create (Vcode_conversion_workbuf_name); - workbuf = Vcode_conversion_reused_workbuf; - } - current = current_buffer; - set_buffer_internal (XBUFFER (workbuf)); - /* We can't allow modification hooks to run in the work buffer. For - instance, directory_files_internal assumes that file decoding - doesn't compile new regexps. */ - Fset (Fmake_local_variable (Qinhibit_modification_hooks), Qt); - Ferase_buffer (); - bset_undo_list (current_buffer, Qt); - bset_enable_multibyte_characters (current_buffer, multibyte ? Qt : Qnil); - set_buffer_internal (current); - return workbuf; -} - - static void code_conversion_restore (Lisp_Object arg) { @@ -7846,7 +7810,12 @@ code_conversion_restore (Lisp_Object arg) if (EQ (workbuf, Vcode_conversion_reused_workbuf)) reused_workbuf_in_use = 0; else - Fkill_buffer (workbuf); + { + ptrdiff_t count = SPECPDL_INDEX (); + specbind (Qbuffer_list_update_hook, Qnil); + Fkill_buffer (workbuf); + unbind_to (count, Qnil); + } } set_buffer_internal (XBUFFER (current)); } @@ -7857,9 +7826,51 @@ code_conversion_save (bool with_work_buf, bool multibyte) Lisp_Object workbuf = Qnil; if (with_work_buf) - workbuf = make_conversion_work_buffer (multibyte); + { + ptrdiff_t count = SPECPDL_INDEX (); + if (reused_workbuf_in_use) + { + Lisp_Object name + = Fgenerate_new_buffer_name (Vcode_conversion_workbuf_name, Qnil); + specbind (Qbuffer_list_update_hook, Qnil); + workbuf = Fget_buffer_create (name); + unbind_to (count, Qnil); + } + else + { + if (NILP (Fbuffer_live_p (Vcode_conversion_reused_workbuf))) + { + specbind (Qbuffer_list_update_hook, Qnil); + Vcode_conversion_reused_workbuf + = Fget_buffer_create (Vcode_conversion_workbuf_name); + unbind_to (count, Qnil); + } + workbuf = Vcode_conversion_reused_workbuf; + } + } record_unwind_protect (code_conversion_restore, Fcons (Fcurrent_buffer (), workbuf)); + if (!NILP (workbuf)) + { + struct buffer *current = current_buffer; + set_buffer_internal (XBUFFER (workbuf)); + /* We can't allow modification hooks to run in the work buffer. For + instance, directory_files_internal assumes that file decoding + doesn't compile new regexps. */ + Fset (Fmake_local_variable (Qinhibit_modification_hooks), Qt); + Ferase_buffer (); + bset_undo_list (current_buffer, Qt); + bset_enable_multibyte_characters (current_buffer, multibyte ? Qt : Qnil); + if (EQ (workbuf, Vcode_conversion_reused_workbuf)) + reused_workbuf_in_use = 1; + else + { + Fset (Fmake_local_variable (Qkill_buffer_query_functions), Qnil); + Fset (Fmake_local_variable (Qkill_buffer_hook), Qnil); + } + set_buffer_internal (current); + } + return workbuf; }