all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ken Raeburn <raeburn@raeburn.org>
To: michael schuldt <mbschuldt@gmail.com>
Cc: Eli Zaretskii <eliz@gnu.org>, emacs-devel@gnu.org
Subject: Re: Should we land Lisp reader optimizations?
Date: Wed, 21 Jun 2017 06:07:01 -0400	[thread overview]
Message-ID: <8A56FEA9-0BE9-4344-AF29-49EE5405EC08@raeburn.org> (raw)
In-Reply-To: <CABhu7fVCneVY74pBbV4MD_aJNU6frv8ALiPkPGaURbVTbjXQDA@mail.gmail.com>

On Jun 20, 2017, at 22:50, michael schuldt <mbschuldt@gmail.com> wrote:

> Since the time spent in GC appears so significant, why not disable GC while reading?
> 
> I have not followed all the previous threads so apologies if this question is uninformed

GC doesn’t happen during reading per se, it happens during evaluation of expressions and when stopping to wait for user input, but whether it happens at those points depends on the amount of storage allocated since the last GC pass.  It’s probably possible to come up with GC heuristics that do better than what we’ve got now, but there are tradeoffs.  The trick is coming up with the right metrics (memory size? CPU time? delay in interactive response? startup speed?) and the right use cases to optimize for.  It’d be relatively easy to improve a couple of numbers, at the cost of a worse experience in other important cases.  GC improvement would be a significant research project of its own, one I’m not solving this week. :-)

But finding simple ways to avoid doing allocations in the first place is a pretty clear win.  Sometimes you get lucky.

My test was parsing each Lisp expression in each of 1447 .elc files (total size over 50MB) and looping over all of that 10 times; that means we started with something like one GC pass per 16 files processed, on average, which doesn’t seem so bad.  (It would be more frequent if we were actually evaluating the Lisp expressions that were read.  But I’m only working on the reader code with these changes.)  With the various patches, it’s more like one GC pass per 23 files scanned.

Disabling GC for the duration of reading an entire file probably wouldn’t make much difference, then.  This one-GC-per-16-files thing is an average, of course; I’d guess the GC probably took place between reading one expression from a file and reading the next expression from the same file, but would there be any benefit from delaying it until we were between files?

Raising the gc-cons-threshold value so that GC happens less often could also be done.  But then you’re likely to get faster memory growth.  It’s something that can be considered, but for the purposes of evaluating changes to the Lisp reader, I figure one less knob to fiddle with is simplest.

In the scratch branch I’ve been working on, with Stefan’s code to load a saved Lisp environment as one big .elc file, I have for now raised the gc-cons-threshold value considerably, because the one big .elc file is big enough to trigger multiple GC passes, and the entire file has to be read and evaluated before interactive use of the Emacs process can start.  But it’s not a very good “fix”, as it’ll affect a lot more than startup.  Perhaps I should reset it to its normal value at the end of loading the file, but that’d likely trigger GC pretty much right away, and I was trying to avoid triggering any GC delays before getting to the point of responding to the user’s keyboard input.  It’ll have to be worked out before we can properly evaluate the performance of the big-elc-file approach….

Ken


  reply	other threads:[~2017-06-21 10:07 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-19 16:58 Should we land Lisp reader optimizations? Eli Zaretskii
2017-06-20  7:08 ` Ken Raeburn
2017-06-20 10:12   ` Ken Raeburn
2017-06-20 15:25     ` Eli Zaretskii
2017-06-20 15:39       ` Clément Pit-Claudel
2017-06-20 16:06         ` Paul Eggert
2017-06-20 23:12       ` John Wiegley
2017-06-21  2:50         ` michael schuldt
2017-06-21 10:07           ` Ken Raeburn [this message]
2017-06-21 17:41           ` Eli Zaretskii
2017-06-22  1:58           ` Richard Stallman
2017-06-22  2:56             ` michael schuldt
2017-06-22  6:25               ` John Wiegley
2017-06-22 13:26           ` Stefan Monnier
2017-06-22  1:57         ` Richard Stallman
2017-06-21  9:46       ` Ken Raeburn
2017-06-21 17:56         ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8A56FEA9-0BE9-4344-AF29-49EE5405EC08@raeburn.org \
    --to=raeburn@raeburn.org \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=mbschuldt@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.