Stack level too deep


#1

I have a tree that I do recursion over the nodes (and then some
recursion inside the nodes…). Two problems:

  1. Stack level too deep (error message)
  2. Speed get really really lousy when the tree is deep. With a small
    shallow tree the speed is nice. I get that the overall time get long but
    the handling of each node is slow in a deep tree.

Any way around these issues? I should say that it’s running in a Rails
environment on Win, Ruby 1.8.2

/Marcus


#2

On 2/28/06, marcus removed_email_address@domain.invalid wrote:

I have a tree that I do recursion over the nodes (and then some
recursion inside the nodes…). Two problems:

  1. Stack level too deep (error message)

what is the maximum depth of the tree? and how do you traverse it?
– henon


#3

marcus wrote:

I have a tree that I do recursion over the nodes (and then some
recursion inside the nodes…). Two problems:

  1. Stack level too deep (error message)
  2. Speed get really really lousy when the tree is deep. With a small
    shallow tree the speed is nice. I get that the overall time get long
    but the handling of each node is slow in a deep tree.

Any way around these issues? I should say that it’s running in a Rails
environment on Win, Ruby 1.8.2

The easiest change is to use BFS instead of DFS - if that’s possible in
your scenario. Alternatives:

  • implement a DFS with your own kind of stack

  • change the way you store things to avoid such a deep recursion

Also, I guess you made sure that there is no loop, i.e. the structure is
actually a tree…

Kind regards

robert

#4

Meinrad R. wrote:

into a loop, but it will not be as easy to read anymore.
That’s exactly the other recommendation I gave. :slight_smile:

robert

#5

On 2/28/06, Robert K. removed_email_address@domain.invalid wrote:

  • change the way you store things to avoid such a deep recursion

[…]

i now remember that i had a similar problem with a deep recursion and
stack
depth. i solved
it by converting the recursive function into a while loop. you can
transform
every recursion
into a loop, but it will not be as easy to read anymore.
– henon


#6

Robert K. skrev:

into a loop, but it will not be as easy to read anymore.

That’s exactly the other recommendation I gave. :slight_smile:

robert

I haven’t received the other mail(s) that is talked about. However:

I’m implementing the composite pattern using acts_as_tree and STI in
ActiveRecord. The thing that is modeled is nodes in a web site structure
that is kind of tree structured (isn’t all web sites?). So I try to loop
over the nodes to do various operations (generate navigations, publish,
distribute etc).

I’m sure that there are ways around this but then you have to code
around stuff because of the language implementation and that doesn’t
feel good at all…

/Marcus


#7

marcus wrote:

  1. Stack level too deep (error message)

You can change the stack size of the Ruby executable with editbin. It’s
part of Visual Studio.


#8

On Feb 28, 2006, at 11:14 AM, marcus wrote:

I’m sure that there are ways around this but then you have to code
around stuff because of the language implementation and that
doesn’t feel good at all…

Well maybe you can take smaller steps to coding around the
implementation, first code a tail-recursive version and then convert
that into an iterative version.


#9

On 28 Aug, 04:13, Justin Ko removed_email_address@domain.invalid wrote:

I would suggest switching to capybara.

Hi Justin,

I tried changing a part of my Gemfile to this:

group :development, :test do
gem ‘rspec-rails’, ‘>= 2.0.0.beta.19’
gem ‘capybara’
end

I am not sure if this is correct or what to do next. I tried “bundle
install” and then “rspec spec/requests”. Capybara was installed but I
still got the stack level too deep error. Could you tell me what to do
or point me to an online resource where this is documented?

Thanks in advance!

Regards,

Daniel
LidströmStockholm, Sweden


#10

I think you’re having this problem:
http://github.com/rspec/rspec-rails/issues#issue/140

  • Toni

#11

On Aug 28, 6:59 am, Daniel Lidström removed_email_address@domain.invalid wrote:

group :development, :test do

Regards,

Daniel Lidström
Stockholm, Sweden


rspec-users mailing list
removed_email_address@domain.invalid://rubyforge.org/mailman/listinfo/rspec-users

Did you remove webrat from the Gemfile?


#12

On Aug 28, 2010, at 11:33 AM, Justin Ko wrote:

or point me to an online resource where this is documented?
Did you remove webrat from the Gemfile?
That won’t help with beta.19, which has a hard dependency on webrat.
beta.20 does not, so you can choose between webrat and capybara.


#13

On 28 Aug, 19:32, David C. removed_email_address@domain.invalid wrote:

On Aug 28, 2010, at 11:33 AM, Justin Ko wrote:

Did you remove webrat from the Gemfile?

That won’t help with beta.19, which has a hard dependency on webrat. beta.20 does not, so you can choose between webrat and capybara.

Thanks for the responses so far. Here’s what I have done:

  • Switched to beta 20:

daniel@ubuntu/home/daniel/programming/rails_projects/sample_app$ cat
Gemfile
source ‘http://rubygems.org

gem ‘rails’, ‘3.0.0.rc’

Bundle edge Rails instead:

gem ‘rails’, :git => ‘git://github.com/rails/rails.git’

gem ‘sqlite3-ruby’, :require => ‘sqlite3’

group :development, :test do
gem ‘rspec-rails’, ‘>= 2.0.0.beta.20’
gem ‘capybara’
end

  • Updated rspec:

daniel@ubuntu/home/daniel/programming/rails_projects/sample_app$ rails
generate rspec:install
identical .rspec
exist spec
conflict spec/spec_helper.rb
Overwrite /home/daniel/programming/rails_projects/sample_app/spec/
spec_helper.rb? (enter “h” for help) [Ynaqdh] Y
force spec/spec_helper.rb
exist autotest
identical autotest/discover.rb

  • Then run the tests again:

daniel@ubuntu/home/daniel/programming/rails_projects/sample_app$ rspec
-b spec
FFFF.F.F.F

Failures:

  1. LayoutLinks should have a Home page at ‘/’
    Failure/Error: response.should have_selector(‘title’, :content =>
    “Home”)
    undefined method `has_selector?’ for
    #ActionDispatch::TestResponse:0x7f0f4ca18cb0

    /usr/lib/ruby/gems/1.8/gems/rspec-expectations-2.0.0.beta.20/

lib/rspec/matchers/has.rb:11:in __send__' # /usr/lib/ruby/gems/1.8/gems/rspec-expectations-2.0.0.beta.20/ lib/rspec/matchers/has.rb:11:inmatches?’
# /usr/lib/ruby/gems/1.8/gems/rspec-expectations-2.0.0.beta.20/
lib/rspec/expectations/handler.rb:11:in handle_matcher' # /usr/lib/ruby/gems/1.8/gems/rspec-expectations-2.0.0.beta.20/ lib/rspec/expectations/extensions/kernel.rb:27:inshould’
# ./spec/requests/layout_links_spec.rb:7
# /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/
core/example.rb:52:in instance_eval' # /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/ core/example.rb:52 # /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/ core/example.rb:86:incall’
# /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/
core/example.rb:86:in with_around_hooks' # /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/ core/example.rb:48 # /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/ core/example.rb:80:incall’
# /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/
core/example.rb:80:in with_pending_capture' # /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/ core/example.rb:79:incatch’
# /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/
core/example.rb:79:in with_pending_capture' # /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/ core/example.rb:47:inrun’
# /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/
core/example_group.rb:222:in run_examples' # /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/ core/example_group.rb:219:inmap’
# /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/
core/example_group.rb:219:in run_examples' # /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/ core/example_group.rb:210:inrun’
# /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/
core/command_line.rb:43:in run_examples' # /home/daniel/.gem/ruby/1.8/gems/activesupport-3.0.0.rc/lib/ active_support/dependencies.rb:219:ininject’
# /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/
core/command_line.rb:43:in each' # /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/ core/command_line.rb:43:ininject’
# /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/
core/command_line.rb:43:in run_examples' # /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/ core/command_line.rb:26:inrun’
# /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/
core/reporter.rb:11:in report' # /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/ core/command_line.rb:23:inrun’
# /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/
core/runner.rb:46:in run_in_process' # /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/ core/runner.rb:37:inrun’
# /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/
core/runner.rb:10
# /usr/bin/rspec:19
.
.
.

I don’t know what to do from here?


#14

On 28 Aug, 21:21, Toni T. removed_email_address@domain.invalid wrote:

Have selector is a webrat matcher. If you’re not using webrat you
can’t use it. Capybara’s matcher is have_css. I suggest you take a
look at capybara docs.

  • Toni

Aha, that makes perfect sense Toni. Thanks!

Daniel


#15

Have selector is a webrat matcher. If you’re not using webrat you
can’t use it. Capybara’s matcher is have_css. I suggest you take a
look at capybara docs.

  • Toni

#16

On Aug 28, 2:44pm, Daniel L. removed_email_address@domain.invalid wrote:

  • Switched to beta 20:
    gem ‘sqlite3-ruby’, :require => ‘sqlite3’
    identical .rspec
    daniel@ubuntu/home/daniel/programming/rails_projects/sample_app$ rspec
    lib/rspec/matchers/has.rb:11:in `send
    core/example.rb:52

    /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/

core/example_group.rb:219:in `run_examples’

/usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/

core/runner.rb:37:in `run’
removed_email_address@domain.invalid://rubyforge.org/mailman/listinfo/rspec-users
Did you run bundle install?