From unknown Tue Jun 17 01:50:51 2025 X-Loop: help-debbugs@gnu.org Subject: bug#77089: [PATCH] Simplify Eshell history de-duplication Resent-From: Morgan Smith Original-Sender: "Debbugs-submit" Resent-CC: johnw@gnu.org, bug-gnu-emacs@gnu.org Resent-Date: Mon, 17 Mar 2025 22:35:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 77089 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: 77089@debbugs.gnu.org Cc: John Wiegley X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: John Wiegley Received: via spool by submit@debbugs.gnu.org id=B.174225085317194 (code B ref -1); Mon, 17 Mar 2025 22:35:04 +0000 Received: (at submit) by debbugs.gnu.org; 17 Mar 2025 22:34:13 +0000 Received: from localhost ([127.0.0.1]:33179 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tuJ2C-0004TG-Ck for submit@debbugs.gnu.org; Mon, 17 Mar 2025 18:34:12 -0400 Received: from lists.gnu.org ([2001:470:142::17]:38812) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tuJ28-0004Rn-9W for submit@debbugs.gnu.org; Mon, 17 Mar 2025 18:34:10 -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 ) id 1tuJ20-0008B0-Lm for bug-gnu-emacs@gnu.org; Mon, 17 Mar 2025 18:34:00 -0400 Received: from mail-mw2nam12olkn2080b.outbound.protection.outlook.com ([2a01:111:f403:2805::80b] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tuJ1x-0004mY-Ss for bug-gnu-emacs@gnu.org; Mon, 17 Mar 2025 18:34:00 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cxYuQbukRZTURiP/uWkuXmwmHh3tNWVO0tceaTUngQi6e/wl4FTuDFnbcXOjmjHatgtPiROR9pUIjXVuYeTSfPd2TQJGR97IYy8KHPxSxe84lIMD8zS/GLBJgj+WzPgFmvowSWwHz/zQu0XACeJNEjxOi5aupEMHSAv9dHV4katY8mwqAQ+NU7NVQCYUzaQUHIYCt30tImoQcXHQ4NMyDrTUI4aNlbTO8c3hqLjlniaIHb+VA4b3Zk6nqMiv4s815p3EuxWdw1EDW00/w2QRKkIxLgvkZK2sWEnGUdhNqhUuItyHoUjF27bF6RExKtINQX4MiL2shpFTzR9Sbns1yA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lsT8z4AKHeFULJuIXssveUlS03tz7ulSfX3UPYn8Sw8=; b=M3CRCBtLTDcZ0xqWrFEuII9xjasHZqbTEmJEPdpbiDJbG+PIg5kO9A8ECZrOECU/PwRHrDLwE/LvEcVAeNa5pDbvDAkMpqY0pprkXXEOM46Eia86On48LPbvutdsGCtPnnqPcQ0dTiK24U7DIgcXgRNpFd5xxuaG7Cq93EKhQDNxTl0gEWL/bEiVSgMtD52c9EhAIXAXaqAFE92sMEPoZTEnM0vPWA44RUIkhjrYp1QeCW4+nRAPs2nVQUsgBFF70sqq2a+LBC5Y3+grjEXEE5BH23UtSfdFTgPzSnybqgsPeXKDiqJmGakoI8IXbEPFKqSO1OGiK+EI+eQDXPbEGw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lsT8z4AKHeFULJuIXssveUlS03tz7ulSfX3UPYn8Sw8=; b=JkrL6Q1uo2Dan0q4lP/bEGRnDABVDeqJvpz4uf73PDsloF5TkMYolC/o53x7l4/HNNgFmwRAN9GmNJO4A+L1RlzCovkv4oR6wv81JfHkKm99ORyHwhMDmP6cu65lJUehQpX66PCt4oYQc4PycWf54H0HUE0bIAb9oztOyveLm9pVAFOOxEq+e6CmUUKHMacxRuyLNDgbplauONurrsLhlflOJLct/0ZFEuF08gOw9zAaiad1fGXyuqr4ok2jzVHGzFJceSS2JLpMRE/FHfI25GTj7Cwx8KOsuJHWj+C7YbUOlWQ9qB5gb1P7JmlSBf9H9u3K+LSUh2Nd7XQeGA5dvg== Received: from CH3PR84MB3424.NAMPRD84.PROD.OUTLOOK.COM (2603:10b6:610:1c4::17) by PH0PR84MB1477.NAMPRD84.PROD.OUTLOOK.COM (2603:10b6:510:170::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8534.33; Mon, 17 Mar 2025 22:33:53 +0000 Received: from CH3PR84MB3424.NAMPRD84.PROD.OUTLOOK.COM ([fe80::5c77:7a58:48ed:9aef]) by CH3PR84MB3424.NAMPRD84.PROD.OUTLOOK.COM ([fe80::5c77:7a58:48ed:9aef%4]) with mapi id 15.20.8534.031; Mon, 17 Mar 2025 22:33:53 +0000 From: Morgan Smith Date: Mon, 17 Mar 2025 18:33:50 -0400 Message-ID: Content-Type: multipart/mixed; boundary="=-=-=" X-ClientProxiedBy: YT2PR01CA0006.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:38::11) To CH3PR84MB3424.NAMPRD84.PROD.OUTLOOK.COM (2603:10b6:610:1c4::17) X-Microsoft-Original-Message-ID: <87y0x3qoc1.fsf@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR84MB3424:EE_|PH0PR84MB1477:EE_ X-MS-Office365-Filtering-Correlation-Id: 1d4e5080-d964-4713-62c8-08dd65a3cba3 X-Microsoft-Antispam: BCL:0; ARA:14566002|461199028|5072599009|19110799003|8060799006|7092599003|15080799006|6092099012|13095399003|440099028|3412199025; X-Microsoft-Antispam-Message-Info: 1CV7ui40iPCPQvBhfwVejLf+Njs02jH3ydLVfObFXQubQG6FJvOizl4m39n1ev6eCm5JAaDIH0aIRY3cs21Yn2PF0nA5/soP/9JEGym3r1gETJXCJZp7D846LeDUmN5MkfXOAL30NMQBo1OuGaNlDovhbvTZ5soyvUjXd7D1NnOcMDO7nQdrtjFJhs+RuG+oMtgFxds1slqsPF5232YSbfHqEOvYr13FzvVP1In1as5rS1Zs4yoDvRBF1yEFKhSsdeFpfvuRIsHsO+eejC9UWU4mlY9ZVtS4W7b/E5wbm6hAPid8MUsoBngR8tF1V94/YTC0YF4cc3PHISYhzGcwLBlu3wV8ufrNijlsHxQ4R+nLz7leyj9P/pQiLXlWxbAYQlGIak6pam0xt75n3KSF1WASzgd1kK0BKIcOxpL4lXF+3ZhBzmmNOPQ3L2j9ahd5QbfZ7rZ/BzttOA6dO8sMNzbaAgYXW0GZsSU3Bn41RpyfRHBX8MOuILUJsrSuRESWIJJJPvsU4GrRiUlGEyFX4yn7aedYSDtUhfz6dDZqTtHOXl8w3n6NKY417mqsyKiNTF6pwlXERrUJzGPFVcIj8DhB1xJiDrnQqSQKkPO3NEFCR13r8Zzh4MPS12uSjg5oeqyOD0NedjxNL2IRpGugdlsedgoTUUhjtQJXGQV5Ddciia12WkmF5HrTY/i1F++SHoHb+rCtRf1swGLSX9pub09Di+w5Dc2en2I6V0Y38iDT3eD1K74I5RCvS+IUL/kQJtJtvYWwimrhFHoU3UQWuINymy5NCkLaLrtLGp2ChOL9y/zcvFhliGTK5sVFTgGvKsKRMs0FPVo6Vmzc+aX8C6tPA/qHXN2HgC8EZ74MXNzb65hkOr+2pk6H+qF/EIo5xnxcUjqkNZNdsrQyMKFuCdLhiGTB8ODOny8K4ZqlM83LXyvxenyKrnqgdZJJtDgjBL4En/8krA4zVGGEKU/bXTKPcJk5Vn83HRbyqCpXA+40wbAUA81hew8xcZm/wXtez3dgAkmQ5664CvVnF9ZqRLFUQ//XOpPGUnDKCh9t1V0ZN6CLSqX0VHjh8C75NytzNOnaqQsjEn6uphAXZkFqes3syMcF/LMHj2XPRKBBnaKFqnnOfvICf1OTVlTHFROQ/Ze6eadd5ytMh7Di7rsn+p5b1tR9SJpSAN2lc9NYFvU= X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: eMqd33a4FkIgnOuIl++upWN5jiYCYg5QGl41Zq+ctfzYA6PSD0IvEN+kKuJxTG+uPvCh6rHa5Y8bd3q/dzw31ZjRuTaMwVMUWThPLm7Kn25N2RtREgF9o03GEqVsBlapoPRDc3qnDUBRmY/3+SgLQn4uJUbisyj10zOzcSJyvF8tYscZtM84Npd43d4uVasccP56yWfXy/ptCC2hOLrFKavxL3EWS2DWAadICk9Jfkah55N5+RCsFqEuSMw/OpbPmjBtK0r+empQAv5bQQylqRXgzUb6KSNFdecpvt9zh9at5LSDo8/4nZNN/O6WT2iIWYwOIeSWnVRlTtjJkHN/JrOcZtj7fVxJ+TqTcw+ceaKDu4BqFbHRiYvqpyM/ryECjEbOkGIEgHRIZskk1krCRH5yzreUNnDhQeEDqD4zDhuBPA7H/w4t27QLN5a8lpqYZ0V6uFsl5x2CQUicHXQIrziFr9Q0F2eoc0jWvwKhIlOkq7X0kP2HuF1JhBNYKdEOmFqQInMvQ9yTPBVzKX1CQbheJ1AM17RrVhQpx22mU1fc2xLNpVn9bk1QTq67VNbNpJn80Hxm3okJcB1TFJL38Y77YwM09G0mbbW1bfkc4zf0X75+YQjTjBOEW5bGZpq2fZsUADf9NRCPlAZ3V2DDw3JV7Iw2hY+iJVLYYbl//Mk0iI8bu0PJ936/0yTtwxLx3s3WFNrZtD9Izijb9+nPuKeP+5OQP+XtVWHnx0TPU0ec+Bpaw+7q9wC47gDuOP4NyN2AqHVOSMN8r6gpB+2NWcgjO2SEKlish6GOM7ZZ2V+ecv3Ih3ValRr9iw3sIVpDOZky6XPI52ssBrhRGzR6K1WmZIgFMuRdb9bhF6dbm7A/56CdVW7xl5O8fVp7CRIaCSrzH8VYs5AlzBZ1vevMmoJzCIhne40tsLm3d/b0i57ntbomk1E0uXNU3IKKkxwLroc/A50joNAJ16h0SAHtPG3yeOOiUZB/Hm2SvKfL8fqPLv+wdxGJBFmFYegwFjaTkJyP+GqUPDmxwA33fHuMyyJa0CIUFxBZldNRX5U9PyJvUuUrD/W0VM3ur26Qv2dN32FPiOL4ixS3ZkBc5msWmPlh2WaaoVshXyTYi7TsnzkHhKn8c1+UuPFzpnT99PZ+Fe/sCC9Km0tJqc8WXV6Iy9Q2J1EiAA2S2k0wnWKQThg550sTkaYnYOhFw5aVk0DG7ZUgWS5Ioh5tjIfsa8WwLdj1zfqxSqNp9Oy3YV6wmH4zD1rqzsh4ZUwS86U+++B9 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1d4e5080-d964-4713-62c8-08dd65a3cba3 X-MS-Exchange-CrossTenant-AuthSource: CH3PR84MB3424.NAMPRD84.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Mar 2025 22:33:53.2337 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR84MB1477 Received-SPF: pass client-ip=2a01:111:f403:2805::80b; envelope-from=Morgan.J.Smith@outlook.com; helo=NAM12-MW2-obe.outbound.protection.outlook.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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.0 (+) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) --=-=-= Content-Type: text/plain Tags: patch Hello! I was noticing a perceptible delay in starting eshell of 0.838 seconds. Turns out it was because I had `eshell-hist-ignoredups' set to 'erase and I had a 5000 line shell-history file. This patch speeds it up for me to 0.011 seconds. --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Simplify-Eshell-history-de-duplication.patch >From 68160b6c84c2f8946caca5a6be274434f4e3d053 Mon Sep 17 00:00:00 2001 From: Morgan Smith Date: Mon, 17 Mar 2025 18:19:21 -0400 Subject: [PATCH] Simplify Eshell history de-duplication This also increases performance significantly for large history files when `eshell-hist-ignoredups' is set to 'erase. * lisp/eshell/em-hist.el (eshell-read-history): Run `delete-duplicate-lines' on the shell history text instead of checking for duplicates at every insertion. --- lisp/eshell/em-hist.el | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/lisp/eshell/em-hist.el b/lisp/eshell/em-hist.el index 3f779f95acd..78ceed4bd6a 100644 --- a/lisp/eshell/em-hist.el +++ b/lisp/eshell/em-hist.el @@ -458,22 +458,17 @@ eshell-read-history (ignore-dups eshell-hist-ignoredups)) (with-temp-buffer (insert-file-contents file) + (when ignore-dups + (delete-duplicate-lines (point-min) (point-max) t + (not (eq ignore-dups 'erase)))) ;; Watch for those date stamps in history files! (goto-char (point-max)) (while (and (< count size) (re-search-backward "^[ \t]*\\([^#\n].*\\)[ \t]*$" nil t)) - (let ((history (match-string 1))) - (when (or (ring-empty-p ring) - (null ignore-dups) - (and (not (string-equal - (ring-ref ring (1- (ring-length ring))) - history)) - (not (and (eq ignore-dups 'erase) - (ring-member ring history))))) - (ring-insert-at-beginning - ring (subst-char-in-string ?\177 ?\n history)) - (setq count (1+ count)))))) + (ring-insert-at-beginning + ring (subst-char-in-string ?\177 ?\n (match-string 1))) + (setq count (1+ count)))) (setq eshell-history-ring ring eshell-history-index nil eshell-hist--new-items 0)))))) -- 2.48.1 --=-=-=-- From unknown Tue Jun 17 01:50:51 2025 X-Loop: help-debbugs@gnu.org Subject: bug#77089: [PATCH] Simplify Eshell history de-duplication Resent-From: John Wiegley Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 18 Mar 2025 01:36:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 77089 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Morgan Smith Cc: 77089@debbugs.gnu.org Received: via spool by 77089-submit@debbugs.gnu.org id=B77089.174226173829956 (code B ref 77089); Tue, 18 Mar 2025 01:36:03 +0000 Received: (at 77089) by debbugs.gnu.org; 18 Mar 2025 01:35:38 +0000 Received: from localhost ([127.0.0.1]:33768 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tuLrl-0007n1-6J for submit@debbugs.gnu.org; Mon, 17 Mar 2025 21:35:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38064) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tuLri-0007lc-Jz for 77089@debbugs.gnu.org; Mon, 17 Mar 2025 21:35:35 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tuLrc-0000Oz-Gg; Mon, 17 Mar 2025 21:35:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=jPjbZFCL5Z34fJrH5DzUo4IMDjuZJ6IsvARuKi/XyIA=; b=qQuHk+WO6cLxPgnQlNQ9 cFsx0XEI2A15tA+yU6bUK9sK+mFebmK+C5W90fNXaOTWZx2x+P5IUDIEVB1fuFE4nUFiX+nXSesIA E6dUbwGG4rnzHkq4CTFmsjzIJuiSFeOjS6W2pU65pqHeEs4lii1YdKtUCvx/sRNDZ17sBUNlEUScn Z5ntTDNhR2wOk78E/0a4/6fj8Kh1cZQ/L+IQp2LMnPzJ2elJldjEJBmlOy57CydgXsi/2t4PHPdo7 tWGeh4Ji9OVTpclJ3njFAoikhjBOsWRPS4GMxIZkdy2j3US6sBghw5vppe8joecfi4n/EfOGLx9f0 MiMFfUFe6MNogQ==; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddugeduudduucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhephffvvefujghffffkfgggtgfgsehtqhertddt reejnecuhfhrohhmpeflohhhnhcuhghivghglhgvhicuoehjohhhnhifsehgnhhurdhorh hgqeenucggtffrrghtthgvrhhnpeeiffdthedviedvtdfffeffffevkeeludejieeltddu feehfefhhfefgeejteefgeenucffohhmrghinhepnhgvfigrrhhtihhsrghnshdrtghomh enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehjohhh nhifodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeikeejkedtleeggedqud ejjeehfeekudeiqdhjohhhnhifpeepghhnuhdrohhrghesnhgvfigrrhhtihhsrghnshdr tghomhdpnhgspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoh epjeejtdekleesuggvsggsuhhgshdrghhnuhdrohhrghdprhgtphhtthhopehmohhrghgr nhdrjhdrshhmihhthhesohhuthhlohhokhdrtghomh X-ME-Proxy: Feedback-ID: ib64945b7:Fastmail From: John Wiegley In-Reply-To: (Morgan Smith's message of "Mon, 17 Mar 2025 18:33:50 -0400") References: Date: Mon, 17 Mar 2025 18:35:21 -0700 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) >>>>> "MS" =3D=3D Morgan Smith writes: MS> I was noticing a perceptible delay in starting eshell of 0.838 seconds. MS> Turns out it was because I had `eshell-hist-ignoredups' set to 'erase a= nd MS> I had a 5000 line shell-history file. MS> This patch speeds it up for me to 0.011 seconds. This is great, I didn=E2=80=99t realize this about =E2=80=98delete-duplicat= e-lines': Identical lines need not be adjacent, unless the argument ADJACENT is non-nil (interactively, with a C-u C-u prefix). This is a more efficient mode of operation, and may be useful on large regions that have already been sorted. So it should accomplish just what the original intended to do, but relying = on a likely better optimized function. --=20 John Wiegley GPG fingerprint =3D 4710 CF98 AF9B 327B B80F http://newartisans.com 60E1 46C4 BD1A 7AC1 4BA2 From unknown Tue Jun 17 01:50:51 2025 X-Loop: help-debbugs@gnu.org Subject: bug#77089: [PATCH] Simplify Eshell history de-duplication Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 18 Mar 2025 12:49:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 77089 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Morgan Smith , Jim Porter Cc: 77089@debbugs.gnu.org, johnw@gnu.org Received: via spool by 77089-submit@debbugs.gnu.org id=B77089.174230208630420 (code B ref 77089); Tue, 18 Mar 2025 12:49:01 +0000 Received: (at 77089) by debbugs.gnu.org; 18 Mar 2025 12:48:06 +0000 Received: from localhost ([127.0.0.1]:38363 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tuWMW-0007uI-L1 for submit@debbugs.gnu.org; Tue, 18 Mar 2025 08:48:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50188) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tuWMT-0007sw-1q for 77089@debbugs.gnu.org; Tue, 18 Mar 2025 08:48:02 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tuWMN-0003i5-Gv; Tue, 18 Mar 2025 08:47:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=WSYdqlw+LDmqSo1PPERAXCGTcO3Qk6Ky/YDflPi/ihs=; b=cIWseD3hblgF cwbfybcLwrkZveQEry8SAGe/XK5+n1EysMSaGIzRO0vTK4nQkyNPxXlqGxODOlj3j+gepgS2CpEe7 iAfRFe7vqYjtK8y5dUT/wPc2UvNFUjWw1Y+7KfMp35BxP8apVuNHSKSEP9aRcMMwlerA9aTOl/Xo4 9F+5vhqtOBW8xfcvSzHZ8gYy5d4B9nD1vGa4nmNfFoGPk2O171kotjplqYlJGh0c6haHYDUWe93BP /wU1ceRh5WJ+8zrIqS2S9/7OpEJHM70Rgc2GTu7zsoEmB0C1DpV/2JhVY2m/i2gf7GM4fk5jzZaCz /Hq+LQQOhO6KCJi2o9/PRQ==; Date: Tue, 18 Mar 2025 14:47:51 +0200 Message-Id: <86ldt2qzd4.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: (message from Morgan Smith on Mon, 17 Mar 2025 18:33:50 -0400) References: X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Cc: John Wiegley > From: Morgan Smith > Date: Mon, 17 Mar 2025 18:33:50 -0400 > > I was noticing a perceptible delay in starting eshell of 0.838 seconds. > Turns out it was because I had `eshell-hist-ignoredups' set to 'erase > and I had a 5000 line shell-history file. > > This patch speeds it up for me to 0.011 seconds. Thanks, I'm adding Jim to the discussion. > >From 68160b6c84c2f8946caca5a6be274434f4e3d053 Mon Sep 17 00:00:00 2001 > From: Morgan Smith > Date: Mon, 17 Mar 2025 18:19:21 -0400 > Subject: [PATCH] Simplify Eshell history de-duplication > > This also increases performance significantly for large history > files when `eshell-hist-ignoredups' is set to 'erase. > > * lisp/eshell/em-hist.el (eshell-read-history): Run > `delete-duplicate-lines' on the shell history text instead of > checking for duplicates at every insertion. > --- > lisp/eshell/em-hist.el | 17 ++++++----------- > 1 file changed, 6 insertions(+), 11 deletions(-) > > diff --git a/lisp/eshell/em-hist.el b/lisp/eshell/em-hist.el > index 3f779f95acd..78ceed4bd6a 100644 > --- a/lisp/eshell/em-hist.el > +++ b/lisp/eshell/em-hist.el > @@ -458,22 +458,17 @@ eshell-read-history > (ignore-dups eshell-hist-ignoredups)) > (with-temp-buffer > (insert-file-contents file) > + (when ignore-dups > + (delete-duplicate-lines (point-min) (point-max) t > + (not (eq ignore-dups 'erase)))) > ;; Watch for those date stamps in history files! > (goto-char (point-max)) > (while (and (< count size) > (re-search-backward "^[ \t]*\\([^#\n].*\\)[ \t]*$" > nil t)) > - (let ((history (match-string 1))) > - (when (or (ring-empty-p ring) > - (null ignore-dups) > - (and (not (string-equal > - (ring-ref ring (1- (ring-length ring))) > - history)) > - (not (and (eq ignore-dups 'erase) > - (ring-member ring history))))) > - (ring-insert-at-beginning > - ring (subst-char-in-string ?\177 ?\n history)) > - (setq count (1+ count)))))) > + (ring-insert-at-beginning > + ring (subst-char-in-string ?\177 ?\n (match-string 1))) > + (setq count (1+ count)))) > (setq eshell-history-ring ring > eshell-history-index nil > eshell-hist--new-items 0)))))) > -- > 2.48.1 >