unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Michael Heerdegen <michael_heerdegen@web.de>
To: Noam Postavsky <npostavs@gmail.com>
Cc: 30626@debbugs.gnu.org
Subject: bug#30626: 26.0.91; Crash when traversing a `stream-of-directory-files'
Date: Wed, 28 Feb 2018 11:58:49 +0100	[thread overview]
Message-ID: <87bmg91ity.fsf@web.de> (raw)
In-Reply-To: <87lgfd52by.fsf@gmail.com> (Noam Postavsky's message of "Tue, 27 Feb 2018 20:29:21 -0500")

Noam Postavsky <npostavs@gmail.com> writes:

> >> #+begin_src emacs-lisp
> >> (seq-doseq (_ (stream-range 1 1000000)) nil)
> >> #+end_src
> >> 
> >> Note that this is executed as a loop due how to streams are
> >> implemented, although the definition of `seq-doseq' looks
> >> recursive.
>
> Doesn't look recursive to me, it expands to a call to seq-do, which uses
> a simple loop.

I was imprecise, I meant that the streams are defined recursively (most
of the time).  Though, it's a delayed type of recursion.  Anyway, I
think that this doesn't matter here.

> > Does anyone has a reasonable idea for avoiding the crash in such
> > programs?
>
> I don't have a quick answer for the general case, but I think it's a bug
> in stream.el that it's creating such large structures in the first
> place.  As far as I understand it, the point of streams is to handle
> long lists by encoding them as
>
>     (FIRST-VALUE . FUNCTION-TO-PRODUCE-REST-OF-LIST)

Yes, that's exactly how it's implemented.  When requesting more elements
from the stream, that becomes

      (FIRST-VALUE .
        (SECOND-VALUE . FUNCTION-TO-PRODUCE-MORE-REST-OF-LIST))

When we loop over the string, the cons whose car is the FIRST-VALUE,
let's call it cons1, is immediately thrown away, and we continue with

      (SECOND-VALUE . FUNCTION-TO-PRODUCE-MORE-REST-OF-LIST)

etc.

AFAIU the problem is that the cons1 still exists in memory until garbage
collection kicks in.  When that happens, the cons1 points to a largely
recursive cons structure, though this structure is never referenced from
Lisp in this form.
  
> so as to avoid allocating large amounts of memory.  Is there an easy way
> to find out what the large structures are, and where they are coming
> from?

I think I've answered that.  At least, I think so.  What I don't
understand is that when I force the `seq-doseq' to call
`garbace-collect' explicitly every 1000 cycles, or so, it doesn't help:
the crash still happens after generating ~ 70 000 elements, or some
more, but I can't avoid the crash, no matter how often I call gc.  So
I'm not sure whether these long lists are the problem or something else.
The FUNCTION-TO-PRODUCE-MORE-REST-OF-LIST looks harmless when I print
it, even after thousands of iterations, so I would not understand why
that could be problematic.  streams.el implements things in a way that
these rest functions are not deeply nested lambdas.


Michael.





  reply	other threads:[~2018-02-28 10:58 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-27  9:22 bug#30626: 26.0.91; Crash when traversing a `stream-of-directory-files' Michael Heerdegen
2018-02-27 11:21 ` Eli Zaretskii
2018-02-27 11:39   ` Michael Heerdegen
2018-02-27 12:08     ` Michael Heerdegen
2018-02-27 18:08       ` Eli Zaretskii
2018-02-28  1:29         ` Noam Postavsky
2018-02-28 10:58           ` Michael Heerdegen [this message]
2018-02-28 16:00             ` Eli Zaretskii
2018-02-28 16:20               ` Michael Heerdegen
2018-02-28 17:22                 ` Eli Zaretskii
2018-02-28 18:25                   ` Michael Heerdegen
2018-03-01 11:25                     ` Michael Heerdegen
2018-03-01 15:00                       ` Eli Zaretskii
2018-03-02 14:11                       ` Noam Postavsky
2018-03-02 15:06                         ` Michael Heerdegen
2018-03-02 15:43                           ` Eli Zaretskii
2018-03-02 20:16                         ` Nicolas Petton
2018-03-02 20:58                           ` Nicolas Petton
2018-03-03  7:56                             ` Michael Heerdegen
2018-03-03  7:54                           ` Michael Heerdegen
2018-03-03  8:47                             ` Nicolas Petton
2018-03-02 21:48                         ` John Mastro
2018-03-03 23:00                           ` Noam Postavsky
2018-03-04 15:56                             ` Noam Postavsky
2018-03-04 17:02                               ` Eli Zaretskii
2018-03-11 18:52                                 ` Noam Postavsky
2018-03-11 20:31                                   ` Eli Zaretskii
2018-03-11 21:51                                     ` Noam Postavsky
2018-03-12  3:28                                       ` Eli Zaretskii
2018-03-13  1:59                                         ` Noam Postavsky
2018-03-13 16:06                                           ` Eli Zaretskii
2018-03-14  0:09                                             ` Noam Postavsky
2018-03-15 16:34                                               ` Eli Zaretskii
2018-03-17 15:53                                                 ` Noam Postavsky
2018-03-17 16:10                                                   ` Eli Zaretskii
2018-03-17 16:27                                                     ` Eli Zaretskii
2018-03-17 17:28                                                       ` Noam Postavsky
2018-03-19 20:05                                                         ` Eli Zaretskii
2019-04-25  3:20             ` Noam Postavsky
2019-04-25  5:19               ` Michael Heerdegen
2019-05-10 13:20                 ` Michael Heerdegen
2019-05-25 20:29                   ` Noam Postavsky
2019-05-26  0:32                     ` Michael Heerdegen
2019-05-26  0:40                       ` Noam Postavsky
2019-05-26  1:15                         ` Michael Heerdegen
2019-06-04  0:26                           ` Noam Postavsky
2018-02-28 11:05         ` Michael Heerdegen
2018-02-28 13:20           ` Nicolas Petton
2018-03-01 10:44         ` Daniel Colascione
2018-03-01 15:51           ` Noam Postavsky
2018-03-01 16:54             ` Michael Heerdegen
2018-03-01 17:15               ` Noam Postavsky
2018-03-02  7:08                 ` Michael Heerdegen
2018-03-02 13:01                   ` Noam Postavsky
2018-03-02 13:13                     ` Michael Heerdegen
2018-03-02 13:04                   ` Michael Heerdegen
2018-02-27 18:00     ` 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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=87bmg91ity.fsf@web.de \
    --to=michael_heerdegen@web.de \
    --cc=30626@debbugs.gnu.org \
    --cc=npostavs@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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).