bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* Re: recursive algorithms and stack overflow
       [not found] <14e2aff5-20e3-03a3-50ae-cfabee5bc406@cs.ucla.edu>
@ 2020-08-26 10:13 ` Bruno Haible
  2020-09-30 14:27   ` Marc Nieper-Wißkirchen
  0 siblings, 1 reply; 2+ messages in thread
From: Bruno Haible @ 2020-08-26 10:13 UTC (permalink / raw)
  To: Paul Eggert, bug-gnulib; +Cc: Marc Nieper-Wißkirchen

[CCing bug-gnulib and Marc Nieper-Wißkirchen.]

Paul Eggert wrote in <https://bugs.gnu.org/42931>:
> Bug#42931 prompted me to change the way 
> that the Gnulib diffseq module recurses so that the stack size is O(log N) 
> rather than O(N). I installed this change into Gnulib, here:
> 
> https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=7aadb23803a8fb71d07e6e87ffb1ca510d86f8ef

Similarly, there was a bug report against libcroco [1] recently, because
libcroco's CSS matching is recursive and can thus trigger stack overflow.

It seems this is something to watch out, when we have recursive algorithms
(which is quite frequent). Data sizes of 100 MB (or even just 100 KB) are
considered "small" by today's computation means; if they can trigger stack
overflow, users are unhappy.

Possible mitigations are:
  - Use iteration instead of recursion when possible - like here in diffseq.h,
  - Use iteration with a simulated heap-allocated stack - it would be useful
    to have the stack module in Gnulib for this (Marc?),
  - Use a recursion depth counter in some context struct, and check it at
    every recursion.

Do we have a list of the Gnulib modules that use recursion? [2]?

Bruno

[1] https://gitlab.gnome.org/Archive/libcroco/-/issues/8
[2] https://stackoverflow.com/questions/45194527/how-to-get-a-warning-for-using-recursion



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: recursive algorithms and stack overflow
  2020-08-26 10:13 ` recursive algorithms and stack overflow Bruno Haible
@ 2020-09-30 14:27   ` Marc Nieper-Wißkirchen
  0 siblings, 0 replies; 2+ messages in thread
From: Marc Nieper-Wißkirchen @ 2020-09-30 14:27 UTC (permalink / raw)
  To: Bruno Haible; +Cc: Marc Nieper-Wißkirchen, Paul Eggert, bug-gnulib

Am Mi., 26. Aug. 2020 um 12:13 Uhr schrieb Bruno Haible <bruno@clisp.org>:

> [CCing bug-gnulib and Marc Nieper-Wißkirchen.]
>
> Paul Eggert wrote in <https://bugs.gnu.org/42931>:
> > Bug#42931 prompted me to change the way
> > that the Gnulib diffseq module recurses so that the stack size is O(log N)
> > rather than O(N). I installed this change into Gnulib, here:
> >
> > https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=7aadb23803a8fb71d07e6e87ffb1ca510d86f8ef
>
> Similarly, there was a bug report against libcroco [1] recently, because
> libcroco's CSS matching is recursive and can thus trigger stack overflow.
>
> It seems this is something to watch out, when we have recursive algorithms
> (which is quite frequent). Data sizes of 100 MB (or even just 100 KB) are
> considered "small" by today's computation means; if they can trigger stack
> overflow, users are unhappy.

I agree with all the points made. (And that's why a language with
proper tail calls like Scheme is so convenient.)

> Possible mitigations are:
>   - Use iteration instead of recursion when possible - like here in diffseq.h,
>   - Use iteration with a simulated heap-allocated stack - it would be useful
>     to have the stack module in Gnulib for this (Marc?),

I am sorry for my silence. I haven't forgotten about this project. I
will submit a patch hopefully soon.

Marc


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-09-30 14:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <14e2aff5-20e3-03a3-50ae-cfabee5bc406@cs.ucla.edu>
2020-08-26 10:13 ` recursive algorithms and stack overflow Bruno Haible
2020-09-30 14:27   ` Marc Nieper-Wißkirchen

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).