From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Spencer Baugh Newsgroups: gmane.emacs.devel Subject: [PATCH 3/3] Start opportunistic GC timer at startup Date: Tue, 17 Nov 2020 19:20:50 -0500 Message-ID: <20201118002050.16426-4-sbaugh@catern.com> References: <20201118002050.16426-1-sbaugh@catern.com> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24886"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Spencer Baugh To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Nov 18 01:24:35 2020 Return-path: Envelope-to: ged-emacs-devel@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 1kfBH1-0006Nf-L1 for ged-emacs-devel@m.gmane-mx.org; Wed, 18 Nov 2020 01:24:35 +0100 Original-Received: from localhost ([::1]:47968 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kfBH0-0003We-K9 for ged-emacs-devel@m.gmane-mx.org; Tue, 17 Nov 2020 19:24:34 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49258) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kfBDW-0000GR-4X for emacs-devel@gnu.org; Tue, 17 Nov 2020 19:20:58 -0500 Original-Received: from venus.catern.com ([68.183.49.163]:50982) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kfBDS-0002aw-NR for emacs-devel@gnu.org; Tue, 17 Nov 2020 19:20:57 -0500 Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=98.7.229.235; helo=localhost; envelope-from=sbaugh@catern.com; receiver= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=catern.com; s=mail; t=1605658854; bh=UdkQaasCDIxPWQWZeRa+zXS9sCOVf1jdxSAhhZW4DiM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=XJL7Eg+aq6yYdehXs4Gk0y78A3x4h8L/kTa3wBNN/zZqy0+V/9ZDc/ndF2m27nNlv FhwtzSMZdc7dgx6wWKJyhegQeBFTD6FSSz/w272u4BQwRWLhEptg76Wky0YKz+L76R 8ZLgL4vjY3rLLwbWuC6psNW1t8wk/L4nZksVuM7I= Original-Received: from localhost (cpe-98-7-229-235.nyc.res.rr.com [98.7.229.235]) by venus.catern.com (Postfix) with ESMTPSA id 16B052DD839; Wed, 18 Nov 2020 00:20:54 +0000 (UTC) X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201118002050.16426-1-sbaugh@catern.com> Received-SPF: pass client-ip=68.183.49.163; envelope-from=sbaugh@catern.com; helo=venus.catern.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/17 19:20:53 X-ACL-Warn: Detected OS = Linux 3.11 and newer 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:259325 Archived-At: --- lisp/startup.el | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/lisp/startup.el b/lisp/startup.el index 9f67dfde12..412ed0ca0e 100644 --- a/lisp/startup.el +++ b/lisp/startup.el @@ -1008,6 +1008,32 @@ the `--debug-init' option to view a complete error backtrace." (when debug-on-error-should-be-set (setq debug-on-error debug-on-error-from-init-file)))) +(defcustom gc-opportunistic-eager-factor 2 + "How eager we should be when GCing while Emacs is idle. +Emacs will call garbage-collect-maybe with this argument to +eagerly GC after gc-estimated-time idle seconds have passed. +If this is nil, we won't perform GC while Emacs is idle. +" + :type 'integer) + +(defvar gc-next-opportunistic-timer nil + "The timer for the next opportunistic GC +This is set by `gc-start-opportunistic'.") + +(defun gc-start-opportunistic () + "Start a timer to GC after `gc-estimated-time' idle seconds. +The GC is performed with `garbage-collect-maybe', and is passed +`gc-opportunistic-eager-factor' as its single argument. +If `gc-opportunistic-eager-factor' is nil, we won't do anything. +This function is itself run by an idle timer at Emacs startup." + (when gc-opportunistic-eager-factor + (when gc-next-opportunistic-timer + (cancel-timer gc-next-opportunistic-timer)) + (setq gc-next-opportunistic-timer + (run-with-idle-timer + gc-estimated-time nil + #'garbage-collect-maybe gc-opportunistic-eager-factor)))) + (defun command-line () "A subroutine of `normal-top-level'. Amongst another things, it parses the command-line arguments." @@ -1420,6 +1446,15 @@ please check its value") (eq face-ignored-fonts old-face-ignored-fonts)) (clear-face-cache))) + ;; Start opportunistic GC (after loading the init file, so we obey + ;; its settings). This is desirable for two reason: + ;; - It reduces the number of times we have to GC in the middle of + ;; an operation. + ;; - It means we GC when the C stack is short, reducing the risk of false + ;; positives from the conservative stack scanning. + (when gc-opportunistic-eager-factor + (run-with-idle-timer 1 t #'gc-start-opportunistic)) + (setq after-init-time (current-time)) ;; Display any accumulated warnings after all functions in ;; `after-init-hook' like `desktop-read' have finalized possible -- 2.28.0