Received: (at 78735) by debbugs.gnu.org; 9 Jun 2025 20:09:01 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Mon Jun 09 16:09:01 2025 Received: from localhost ([127.0.0.1]:57952 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1uOinj-0007wK-8F for submit <at> debbugs.gnu.org; Mon, 09 Jun 2025 16:09:01 -0400 Received: from mail-4316.protonmail.ch ([185.70.43.16]:18513) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <pipcet@HIDDEN>) id 1uOinW-0007tJ-Ds for 78735 <at> debbugs.gnu.org; Mon, 09 Jun 2025 16:08:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1749499719; x=1749758919; bh=LcV6dj3b4bvrxMz2HnEViXRvk6F++crDnwNMLQ9CcCQ=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=KDXlYaIVQbWEFX7i1k823HmsyGB+OS+NYs+OA+YE/N1rar64ihaiVxeLQqAF5zofP doOYKeH2rO75F9EIaNubgAZr23D0dXDyYgfDylDvPLF+eYT/+bBXWm6M1KL3PTC2tZ JVX2Zyl4aCiYu2s84SJQBYN2InwIeY4rDaHrjEUg2rVZCtBFsk5KGDNpP+Ma017hLe AgAHNmu2YowytHaKIfN1YpWxndTw0Og9qCnoW7aOPJyVMnWtjT5bh9Xtb8NjOnFnYj ep6FkFjf2fWNa3IFS5g1td3aIM8lwbeqtMAWiIn0FxJdX1dpovVgeU1JAUionM4eES LlG1dK59cS5xg== Date: Mon, 09 Jun 2025 20:08:36 +0000 To: Helmut Eller <eller.helmut@HIDDEN> From: Pip Cet <pipcet@HIDDEN> Subject: Re: bug#78735: feature/igc: [PATCH] Reduce the size of the kbd-buffer GC root Message-ID: <87y0u03cg0.fsf@HIDDEN> In-Reply-To: <87v7p4g10y.fsf@HIDDEN> References: <87v7p4g10y.fsf@HIDDEN> Feedback-ID: 112775352:user:proton X-Pm-Message-ID: cb1733aa83d308e01d9e937e36763256985794af MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 78735 Cc: 78735 <at> debbugs.gnu.org X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.0 (-) "Helmut Eller" <eller.helmut@HIDDEN> writes: > This is a proposal to reduce of the size of the kbd-buffer root. > Currently the kdb-buffer is an area of ~250kb that is scanned > ambiguously. > > With the patch, instead of tracing the entire kbd_buffer, we only scan > the region from kbd_fetch_ptr - 1 to kbd_store_ptr + 1. The -1/+1 is > supposed to cover the cases where MPS stops the mutator while those > pointers are being updated. If the kbd_buffer is empty, then only 180 > bytes are scanned. It's still scanned ambiguously. That sounds great to me. > +static union buffered_input_event * > +prev_kbd_event (union buffered_input_event *kbd_buffer, > +=09=09union buffered_input_event *ptr) > +{ > + return ptr =3D=3D kbd_buffer ? kbd_buffer + KBD_BUFFER_SIZE - 1 : ptr = - 1; > +} > + > +static union buffered_input_event * > +next_kbd_event (union buffered_input_event *kbd_buffer, > +=09=09union buffered_input_event *ptr) > +{ > + return ptr =3D=3D kbd_buffer + KBD_BUFFER_SIZE - 1 ? kbd_buffer : ptr = + 1; > +} Just out of curiosity, is there a reason for the extra kbd_buffer argument? Since this code is replicated a few times, maybe it would be better to keep next_kbd_event in keyboard.c identical to the one in igc.c. Maybe not, though... > + union buffered_input_event *fetch > + =3D prev_kbd_event (kbd_buffer, kbd_fetch_ptr); > + union buffered_input_event *store > + =3D next_kbd_event (kbd_buffer, kbd_store_ptr); > + > + if (fetch < store) > + return scan_ambig (ss, fetch, store, closure); I think this will fail if kbd_store_ptr + 1 =3D=3D kbd_fetch_ptr (i.e. the kbd_buffer is full)? if (fetch < store - 1) should work, though, and it's not like this case is common enough to worry about scanning the same event twice. Pip
bug-gnu-emacs@HIDDEN
:bug#78735
; Package emacs
.
Full text available.Received: (at submit) by debbugs.gnu.org; 9 Jun 2025 19:37:09 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Mon Jun 09 15:37:09 2025 Received: from localhost ([127.0.0.1]:57750 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1uOiIu-0002Y5-8d for submit <at> debbugs.gnu.org; Mon, 09 Jun 2025 15:37:09 -0400 Received: from lists.gnu.org ([2001:470:142::17]:57994) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <eller.helmut@HIDDEN>) id 1uOiIq-0002Vm-Qj for submit <at> debbugs.gnu.org; Mon, 09 Jun 2025 15:37:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <eller.helmut@HIDDEN>) id 1uOiId-0006ug-QI for bug-gnu-emacs@HIDDEN; Mon, 09 Jun 2025 15:36:51 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <eller.helmut@HIDDEN>) id 1uOiIb-000456-Nc for bug-gnu-emacs@HIDDEN; Mon, 09 Jun 2025 15:36:51 -0400 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-441ab63a415so48644295e9.3 for <bug-gnu-emacs@HIDDEN>; Mon, 09 Jun 2025 12:36:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749497807; x=1750102607; darn=gnu.org; h=mime-version:user-agent:message-id:date:subject:to:from:from:to:cc :subject:date:message-id:reply-to; bh=FxrgLnE6VyxDp7YZaNOj10PNt3a9fh4QtFMflRtFl+Y=; b=kwv7xAbQb1tJ2RzWxDMp0tz2C1ywsRAO/LYpDxWt5MjQhuDHelpSGo2M0vRhEjhHiO q71rK3zO7lQrUzu3m5egikjZLXpq3OUqW7uZBiH1WqIm+iiRuD0HQLEW6gAQ2C9z2fn0 hLIL+xU6CJPb2evKiid56DoUnmFs6YkSqqqLYK13IldYEt5q2HvEfdUZgkw/rJFH8Gqb rOYV7XVv7OgCUMI7JN6hxBlfLaF61GQxgNddCQSErqQqhE69pI/TN2bKqV/XUl7VbLhU FvYbgKOK0DNXXuoKFtVwCfS9gwbIhXUQOiLHJogwVSvbXSOPAWn7C5i5U8TvUV2scAzP 6ZAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749497807; x=1750102607; h=mime-version:user-agent:message-id:date:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FxrgLnE6VyxDp7YZaNOj10PNt3a9fh4QtFMflRtFl+Y=; b=fWH5TR3c8c4WScYY5XRncIIKWWay8AFrX8nT8B8MqYxEPHZd3xd36f1ELd3DIbJCD1 n6LkTJXHRA1yNqR2kYdNLCxtdRGKZ7qMcbOm+XBV3MNkSv29/rgmZ9gp85YxLzqcbfJX GiNK7KIaYGzwQ+wUDM/RQdrj0C+42fS/FoF4LfUObK7/e7NBb0cNo9lrfhb9awiHw/WS 5BADZslX3oIgnDkmhPveksvkinCOKZcJlZPHHFt7FOn5X8qG87gkF2qx5MbiSKR0TPQv NkZOepgp3EKixZIcBTDrvhcGfrzweEwm/8iesFU6CTeiPmjymQq1TOkkof3QVq7bd5Yy +8Xw== X-Gm-Message-State: AOJu0Yy34sUG2PKsPxvFPtMwJLdwklIhWTZPfZ6fzvlYbGBIQhHEjGQT Qf4RxpRs9XQggYePeC8d/vKRLZaN+0UluJHeI2cVEFgubFegHI62mZlxDa8rlw== X-Gm-Gg: ASbGncuOiw80tBqlCCqiz22fD+O3K82LNsQ+52qzum7jhk0nB26Jhe/WZOFTDsp9qrv rw9waVdJNDNahBJ7UhKonr3B7B5DcXrncqXFPA0QbR+XLy1kJ/6nvDisc44ja5VBz6ewuKawjOM dDGmVWl/dy82N0iLEwo++sEEG6vyMPj4YCYOZBnv2Nbg9EUYbDSYZq4H0MKWY218vTerPo6u8ED kvhULCo3tGYGTwPHQlsuOxNtA8WNVDAVn0Y+BDWggKKfzd7TAwJxCB5sMAPSXghHzQSJBIQ7TYi iwvGXZETi7jlts/OMiXIX5o+p9Dpro7apXVC6RtjFcdC1bcfqRmjyhi8NN5K+oo9ECmuY3QUghD hIl2tCsEf3xm/FprjgLM= X-Google-Smtp-Source: AGHT+IENANJWap2bniZjwCdeKI0ctruYBKr6Pe2rU2GkMrOxDG47Xj1TWO9pxAzBTb+Fz4wntIrChA== X-Received: by 2002:a05:600c:1c95:b0:453:a95:f07d with SMTP id 5b1f17b1804b1-4531de05552mr220105e9.10.1749497806732; Mon, 09 Jun 2025 12:36:46 -0700 (PDT) Received: from caladan (dial-184179.pool.broadband44.net. [212.46.184.179]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4526e0563b6sm117527515e9.7.2025.06.09.12.36.45 for <bug-gnu-emacs@HIDDEN> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jun 2025 12:36:45 -0700 (PDT) From: Helmut Eller <eller.helmut@HIDDEN> To: bug-gnu-emacs@HIDDEN Subject: feature/igc: [PATCH] Reduce the size of the kbd-buffer GC root X-Debbugs-Cc: Date: Mon, 09 Jun 2025 21:36:45 +0200 Message-ID: <87v7p4g10y.fsf@HIDDEN> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=eller.helmut@HIDDEN; helo=mail-wm1-x334.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -0.0 (/) --=-=-= Content-Type: text/plain This is a proposal to reduce of the size of the kbd-buffer root. Currently the kdb-buffer is an area of ~250kb that is scanned ambiguously. With the patch, instead of tracing the entire kbd_buffer, we only scan the region from kbd_fetch_ptr - 1 to kbd_store_ptr + 1. The -1/+1 is supposed to cover the cases where MPS stops the mutator while those pointers are being updated. If the kbd_buffer is empty, then only 180 bytes are scanned. It's still scanned ambiguously. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Reduce-the-size-of-the-kbd-buffer-GC-root.patch From d1e9eeb7d3cfea48d1037564fda50b511e80a52b Mon Sep 17 00:00:00 2001 From: Helmut Eller <eller.helmut@HIDDEN> Date: Mon, 9 Jun 2025 18:28:10 +0200 Subject: [PATCH] Reduce the size of the kbd-buffer GC root * src/igc.c (root_create_kbd_buffer): New. (root_create_main_thread): Use it. (scan_kbd_buffer_ambig): New. The actual scan function. (next_kbd_event, prev_kbd_event): New helpers, similar to next_kbd_event in keyboard.c. * src/keyboard.c (init_keyboard): Move the GC root creation code to root_create_kbd_buffer in igc.c. --- src/igc.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/keyboard.c | 4 ---- 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/src/igc.c b/src/igc.c index f63b0fe8c88..5f7a1a78cda 100644 --- a/src/igc.c +++ b/src/igc.c @@ -60,6 +60,7 @@ #include "thread.h" #include "treesit.h" #include "termchar.h" +#include "keyboard.h" #ifdef HAVE_WINDOW_SYSTEM #include TERM_HEADER #endif /* HAVE_WINDOW_SYSTEM */ @@ -1725,6 +1726,48 @@ scan_tty_list (mps_ss_t ss, void *start, void *end, void *closure) return MPS_RES_OK; } +static union buffered_input_event * +prev_kbd_event (union buffered_input_event *kbd_buffer, + union buffered_input_event *ptr) +{ + return ptr == kbd_buffer ? kbd_buffer + KBD_BUFFER_SIZE - 1 : ptr - 1; +} + +static union buffered_input_event * +next_kbd_event (union buffered_input_event *kbd_buffer, + union buffered_input_event *ptr) +{ + return ptr == kbd_buffer + KBD_BUFFER_SIZE - 1 ? kbd_buffer : ptr + 1; +} + +static mps_res_t +scan_kbd_buffer_ambig (mps_ss_t ss, void *start, void *end, void *closure) +{ + igc_assert (start == kbd_buffer); + igc_assert (end == kbd_buffer + ARRAYELTS (kbd_buffer)); + + /* Instead of tracing the entire kbd_buffer, only scan the region from + kbd_fetch_ptr - 1 to kbd_store_ptr + 1. The -1/+1 is supposed to + cover the cases where MPS stops the mutator while those pointers + are being updated. */ + + union buffered_input_event *fetch + = prev_kbd_event (kbd_buffer, kbd_fetch_ptr); + union buffered_input_event *store + = next_kbd_event (kbd_buffer, kbd_store_ptr); + + if (fetch < store) + return scan_ambig (ss, fetch, store, closure); + else + { + mps_res_t res + = scan_ambig (ss, fetch, kbd_buffer + KBD_BUFFER_SIZE, closure); + if (res == MPS_RES_OK) + res = scan_ambig (ss, kbd_buffer, store, closure); + return res; + } +} + /*********************************************************************** Default pad, fwd, ... ***********************************************************************/ @@ -2905,6 +2948,14 @@ root_create_tty_list (struct igc *gc) scan_tty_list, "tty-list"); } +static void +root_create_kbd_buffer (struct igc *gc) +{ + root_create (gc, kbd_buffer, kbd_buffer + ARRAYELTS (kbd_buffer), + mps_rank_ambig (), scan_kbd_buffer_ambig, NULL, + true, "kbd-buffer"); +} + static void root_create_main_thread (struct igc *gc) { @@ -4934,6 +4985,7 @@ make_igc (void) root_create_main_thread (gc); root_create_exact_ptr (gc, ¤t_thread); root_create_exact_ptr (gc, &all_threads); + root_create_kbd_buffer (gc); enable_messages (gc, true); return gc; diff --git a/src/keyboard.c b/src/keyboard.c index 72c6e4c17d8..1c2b4ba9e63 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -12892,10 +12892,6 @@ delete_kboard (KBOARD *kb) void init_keyboard (void) { -#ifdef HAVE_MPS - igc_root_create_ambig (kbd_buffer, kbd_buffer + ARRAYELTS (kbd_buffer), - "kbd-buffer"); -#endif /* This is correct before outermost invocation of the editor loop. */ command_loop_level = -1; quit_char = Ctl ('g'); -- 2.39.5 --=-=-=--
Helmut Eller <eller.helmut@HIDDEN>
:bug-gnu-emacs@HIDDEN
.
Full text available.bug-gnu-emacs@HIDDEN
:bug#78735
; Package emacs
.
Full text available.
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997 nCipher Corporation Ltd,
1994-97 Ian Jackson.