From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Increase gc-cons-threshold during package-init? Date: Mon, 19 Feb 2018 16:15:44 -0500 Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1519074918 16915 195.159.176.226 (19 Feb 2018 21:15:18 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 19 Feb 2018 21:15:18 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Feb 19 22:15:14 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1enslg-0001ql-SC for ged-emacs-devel@m.gmane.org; Mon, 19 Feb 2018 22:14:36 +0100 Original-Received: from localhost ([::1]:52412 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ensni-0003VO-US for ged-emacs-devel@m.gmane.org; Mon, 19 Feb 2018 16:16:42 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56936) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ensnQ-0003TW-S3 for emacs-devel@gnu.org; Mon, 19 Feb 2018 16:16:25 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ensnN-0002nR-HT for emacs-devel@gnu.org; Mon, 19 Feb 2018 16:16:24 -0500 Original-Received: from [195.159.176.226] (port=34229 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ensnN-0002mr-8r for emacs-devel@gnu.org; Mon, 19 Feb 2018 16:16:21 -0500 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1ensl1-0007hz-Ak for emacs-devel@gnu.org; Mon, 19 Feb 2018 22:13:55 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 54 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:9YKOq4ZOcaUc1d9FoMdzi3j4vlo= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:223449 > With Emacs now calling package-initialize on its own, Not sure what you mean by "now": it's been the case since Emacs-24.1 (recent changes on `master` have only moved the time at which it takes place). > that emacs startup was now entailing 3 times as many gc calls during > startup as before. One guess is that my init file was lexically > binding gc-cons-threshold to 64MB --- Lexically-binding it would have no effect on the GC, and since that var is declared as dynamically scoped, it was probably dynamically bound. Have you checked how much extra time is spent in the GC because of those extra calls? > the default gc-cons-threshold of 800K is likely from the past and > could be increased. This is a misunderstanding: the real gc-cons-threshold is computed dynamically based on the heap size (see gc-cons-percentage). Maybe those values need to be tweaked because tradeoffs have shifted somewhat, but it doesn't seem very likely. The problem with the above GC calls is much more fundamental and unrelated to the actual values we choose: during periods of initialization, programs typically allocate a lot of memory without generating much garbage. So during those times running a GC tends to be a waste of effort (we scan the whole heap only to find a few crumbs here and there). People often look at situations like yours and conclude that gc-cons-threshold is too small. Yes, it's too small for those cases, but bumping it once and forall makes things worse for the "usual" case, leading to increased heap size, fragmentation, and longer pauses during normal operation (tho this "usual case" is much more difficult to measure). There's no sadly way the GC can magically know that the last N megabytes of allocation generated very little garbage, tho. Maybe should bump those gc-knobs around the startup.el code (or maybe more generally we should bump those knobs while loading a file). > Even if we leave the default as is, it might make sense to temporarily > increase gc-cons-threshold within package-initialize Right. Tho doing this will likely cause a GC to happen right after package-initialize, i.e. just before loading your ~/.emacs. Better would be to bump it around both, I guess. Stefan