You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
RubyTree uses recursion for methods such as each and detached_subtree_copy. This is ok for smaller well-balanced trees, but fails for unbalanced trees when Fiber or Threads are involved.
Constructing and Walking a Linear Tree
See the following example method to construct a linear tree:
This runs fine when executed in the main thread...
puts"Run test in the main thread"run_test()
...but fails when a Fiber or Thread is involved:
puts"Run test in a fiber"beginFiber.newdorun_test()end.resumerescueSystemStackErrorputs"Fiber died."endputs"Run test in a thread"beginThread.abort_on_exception=trueThread.newdorun_test(600)# 600 is not chosen arbitrary: this is the first number where it fails here.endsleep(3)rescueSystemStackErrorputs"Thread died."end
Note that the recursion depth between Fiber and Thread differs.
Demo Output
The example script above produces the following output with my machine:
% ./example.rb
Run test in the main thread
Run test in a fiber
Fiber died.
Run test in a thread
Thread died.
Possible Solution
This should be resolvable by replacing the recursion in each, detached_subtree_copy and elsewhere with the respective iterative representation. each could possibly be fixed like this:
Thank you for highlighting this. I was actually planning to replace recursions at some point of time. I will review the issue and put in a few test cases to start with.
Just out of curiosity, would you be able to share the use case where you need this large volume of nodes?
We are using rubytree to display different kinds of taxonomies. The graphs are built using user input and sometimes users create very long branches (probably by accident). We will eventually filter those branches, but for that we have to find them first. Note that the example above is quite artificial; if the node names are longer, it should crash with a smaller depth. We had one case where it crashed for a tree of depth 40.
RubyTree uses recursion for methods such as
each
anddetached_subtree_copy
. This is ok for smaller well-balanced trees, but fails for unbalanced trees when Fiber or Threads are involved.Constructing and Walking a Linear Tree
See the following example method to construct a linear tree:
This runs fine when executed in the main thread...
...but fails when a Fiber or Thread is involved:
Note that the recursion depth between Fiber and Thread differs.
Demo Output
The example script above produces the following output with my machine:
Possible Solution
This should be resolvable by replacing the recursion in
each
,detached_subtree_copy
and elsewhere with the respective iterative representation.each
could possibly be fixed like this:The text was updated successfully, but these errors were encountered: