From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Gerd =?UTF-8?Q?M=C3=B6llmann?= Newsgroups: gmane.emacs.bugs Subject: bug#57727: 29.0.50; Optimize tty display updates Date: Sun, 11 Sep 2022 12:03:45 +0200 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22209"; mail-complaints-to="usenet@ciao.gmane.io" To: 57727@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Sep 11 12:04:47 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oXJpX-0005fV-Ac for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 11 Sep 2022 12:04:47 +0200 Original-Received: from localhost ([::1]:35956 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oXJpV-0004By-OD for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 11 Sep 2022 06:04:45 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46374) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oXJoo-00049X-Gj for bug-gnu-emacs@gnu.org; Sun, 11 Sep 2022 06:04:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:52050) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oXJoo-0006P4-86 for bug-gnu-emacs@gnu.org; Sun, 11 Sep 2022 06:04:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oXJon-0007Dx-Ra for bug-gnu-emacs@gnu.org; Sun, 11 Sep 2022 06:04:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Gerd =?UTF-8?Q?M=C3=B6llmann?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 11 Sep 2022 10:04:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 57727 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.166289064127759 (code B ref -1); Sun, 11 Sep 2022 10:04:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 11 Sep 2022 10:04:01 +0000 Original-Received: from localhost ([127.0.0.1]:40749 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oXJoj-0007Db-5w for submit@debbugs.gnu.org; Sun, 11 Sep 2022 06:04:00 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:41050) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oXJoe-0007DR-6P for submit@debbugs.gnu.org; Sun, 11 Sep 2022 06:03:56 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48290) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oXJod-00047t-Jh for bug-gnu-emacs@gnu.org; Sun, 11 Sep 2022 06:03:51 -0400 Original-Received: from mail-ed1-x52a.google.com ([2a00:1450:4864:20::52a]:40637) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oXJob-0006Ob-C6 for bug-gnu-emacs@gnu.org; Sun, 11 Sep 2022 06:03:51 -0400 Original-Received: by mail-ed1-x52a.google.com with SMTP id m1so8772076edb.7 for ; Sun, 11 Sep 2022 03:03:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:message-id:date:subject:to:from:from:to:cc:subject :date; bh=2/xLPqVIQYRVwj9FUzolo4dhro2VfndkzPuXBnd/hE8=; b=ZWSMu0H3mdA5yc15lzgtP4MLXS+kUWA1+F/ZL6FUSlpTNIRMesOK+bSVS9gfS/5+XQ LB9q9OwJADOoan4bDwpgKXcX0MP24tHTWvCpLOcFiMw6glE7e40jEbmUzk3glVmMMmO1 P+nXIR4EiRl3x78ExfNorSEHQpdRpt0WtihTcxhK9+XmCpaCypLqExRbF6L9AelhmPXC VuD5qeN7OCIa01omntzekgdvuBohbuo2w2RzxfIMbSugdZiu5tdKn9jsACOzPKk0u0E8 A9wO8J8DDaO2/wt9cRZITP4qBYJjxytkeCOJnnFxXL0eEE5gIYFRNuPiQXRPyf2o/zCW fP3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:subject:to:from:x-gm-message-state :from:to:cc:subject:date; bh=2/xLPqVIQYRVwj9FUzolo4dhro2VfndkzPuXBnd/hE8=; b=bCMeXjL1QkAP/EC0eULtqcYyJCyCrZgjOeFD0UBGvbvRCAHhmLxfPy5ahAdlQ5jwFz wcC4MDSAAoUk46auaOA/rsl7tVLqIWs9MTRFc2369KdSe9HPxWMTZlCx0HeKaTOAI5vy vLx4aTCzWvcDUbl4rYy8U/t9XJmIngCXupcjF7ZZ0W9RiJ9v0oqQV47Zj1/r/31nfct+ Ulk8AepK4dBvYqj2YQ2IzMV1NVjk8kJdFY0oGHbJMGVI+exfhoVHEef+LjSqt3e4j4Sz +AjplJh1d8QsEsQL7QzvMjw4UF8F0y4RAuvh1LlSCBWxYo6RjhUBGMrnSb1OjvWxD4RZ ep8A== X-Gm-Message-State: ACgBeo0cJ9EfNo47j1e51R4ZxOKiV70pVdIBPE4200UBtGYATjfSLCWB hWnVHsXnQBPzfvN2S2WYw8j9vRhA6hs= X-Google-Smtp-Source: AA6agR49k4aKMSiD5RkxLcqSQuU1p5NtDdAk/mLkM/tJ/kRIyNKqfSsAAzSxd8nAl4+fQVCnA3IxFg== X-Received: by 2002:a05:6402:2802:b0:43a:9098:55a0 with SMTP id h2-20020a056402280200b0043a909855a0mr18087346ede.179.1662890627020; Sun, 11 Sep 2022 03:03:47 -0700 (PDT) Original-Received: from Mini.fritz.box (pd9e36635.dip0.t-ipconnect.de. [217.227.102.53]) by smtp.gmail.com with ESMTPSA id q10-20020a50c34a000000b0044838efb8f8sm3711221edb.25.2022.09.11.03.03.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Sep 2022 03:03:46 -0700 (PDT) Received-SPF: pass client-ip=2a00:1450:4864:20::52a; envelope-from=gerd.moellmann@gmail.com; helo=mail-ed1-x52a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:242134 Archived-At: --=-=-= Content-Type: text/plain This is a wishlist item for the implementation of what was discussed recently on emacs-devel, namely using a larger output buffer, and avoiding fflush as a means of improving tty display update speed. The patch below is my first take on that. It adds a low-level interface consisting of two functions tty--set-output-buffer-size and tty-output-buffer-size to change and retrieve the output buffer size of a device. A buffer size of 0 is taken to mean "do what we did since 1991, and a non-zero value is used as the buffer size set with setvbuf. Default is currently to do everything as it always was. One has to do something like (tty--set-output-buffer-size (* 64 1024)) to change to the new behavior. Feedback welcome, especially for the default, i.e. leaving everything as-is, and for the Lisp interface. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Optimize-tty-display-updates.patch Content-Description: patch for master >From 597d17f6ecc866328e3c5c3438b1d7fec3b2bbea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerd=20M=C3=B6llmann?= Date: Sun, 11 Sep 2022 11:42:18 +0200 Subject: [PATCH] Optimize tty display updates * src/dispnew.c (update_frame_1): Don'f flush if tty's output_buffer_size is non-zero. * src/sysdep.c (init_sys_modes): Setvbuf depending on the tty's output_buffer_size. * src/term.c (Ftty__set_output_buffer_size, Ftty__output_buffer_size): Low-level interface for setting and retrieving a tty's output buffer size. (syms_of_term): Defsubr the new functions. * src/termchar.h (struct tty_display_info): New member output_buffer_size. --- src/dispnew.c | 4 +++- src/sysdep.c | 5 ++++- src/term.c | 39 +++++++++++++++++++++++++++++++++++++++ src/termchar.h | 5 +++++ 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/dispnew.c b/src/dispnew.c index 8932f103f1..b786f0f1ba 100644 --- a/src/dispnew.c +++ b/src/dispnew.c @@ -4929,7 +4929,9 @@ update_frame_1 (struct frame *f, bool force_p, bool inhibit_id_p, { if (MATRIX_ROW_ENABLED_P (desired_matrix, i)) { - if (FRAME_TERMCAP_P (f)) + /* Note that output_buffer_size being 0 means that we want the + old default behavior of flushing output every now and then. */ + if (FRAME_TERMCAP_P (f) && FRAME_TTY (f)->output_buffer_size == 0) { /* Flush out every so many lines. Also flush out if likely to have more than 1k buffered diff --git a/src/sysdep.c b/src/sysdep.c index efd9638b07..abb385d138 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -1304,7 +1304,10 @@ init_sys_modes (struct tty_display_info *tty_out) } #endif /* F_GETOWN */ - setvbuf (tty_out->output, NULL, _IOFBF, BUFSIZ); + const size_t buffer_size = (tty_out->output_buffer_size + ? tty_out->output_buffer_size + : BUFSIZ); + setvbuf (tty_out->output, NULL, _IOFBF, buffer_size); if (tty_out->terminal->set_terminal_modes_hook) tty_out->terminal->set_terminal_modes_hook (tty_out->terminal); diff --git a/src/term.c b/src/term.c index 2e43d89232..8e19c96672 100644 --- a/src/term.c +++ b/src/term.c @@ -2400,6 +2400,43 @@ DEFUN ("resume-tty", Fresume_tty, Sresume_tty, 0, 1, 0, return Qnil; } +DEFUN ("tty--set-output-buffer-size", Ftty__set_output_buffer_size, + Stty__set_output_buffer_size, 1, 2, 0, doc: + /* Set the output buffer size for a TTY. + +SIZE zero means use the system's default value. If SIZE is +non-zero,this also avoids flushing the output stream. + +TTY may be a terminal object, a frame, or nil (meaning the selected +frame's terminal). + +This function temporarily suspends and resumes the terminal +device. */) + (Lisp_Object size, Lisp_Object tty) +{ + if (!TYPE_RANGED_FIXNUMP (size_t, size)) + error ("Invalid output buffer size"); + Fsuspend_tty(tty); + struct terminal *terminal = decode_tty_terminal (tty); + terminal->display_info.tty->output_buffer_size + = XFIXNUM (size) <= 0 ? 0 : XFIXNUM (size); + return Fresume_tty(tty); +} + +DEFUN ("tty--output-buffer-size", Ftty__output_buffer_size, + Stty__output_buffer_size, 0, 1, 0, doc: + /* Return the output buffer size of TTY. + +TTY may be a terminal object, a frame, or nil (meaning the selected +frame's terminal). + +A value of zero means TTY uses the system's default value. */) + (Lisp_Object tty) +{ + struct terminal *terminal = decode_tty_terminal (tty); + return make_fixnum (terminal->display_info.tty->output_buffer_size); +} + /*********************************************************************** Mouse @@ -4556,6 +4593,8 @@ syms_of_term (void) defsubr (&Stty_top_frame); defsubr (&Ssuspend_tty); defsubr (&Sresume_tty); + defsubr (&Stty__set_output_buffer_size); + defsubr (&Stty__output_buffer_size); #ifdef HAVE_GPM defsubr (&Sgpm_mouse_start); defsubr (&Sgpm_mouse_stop); diff --git a/src/termchar.h b/src/termchar.h index 49560dbc2a..0f17246411 100644 --- a/src/termchar.h +++ b/src/termchar.h @@ -53,6 +53,11 @@ #define EMACS_TERMCHAR_H FILE *output; /* The stream to be used for terminal output. NULL if the terminal is suspended. */ + /* Size of output buffer. A value of zero means use the default of + BUFIZE. If non-zero, also minimize writes to the tty by avoiding + calls to flush. */ + size_t output_buffer_size; + FILE *termscript; /* If nonzero, send all terminal output characters to this stream also. */ -- 2.37.3 --=-=-=--