Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8921081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:26:37+00:00 2026-06-15T06:26:37+00:00

Fibers are a relatively new concept to me. I’m aware that each fiber’s stack

  • 0

Fibers are a relatively new concept to me. I’m aware that each fiber’s stack size is limited to 4kB and I keep reading that I should “beware” of this. What exactly are the real world consequences of this limit?

Edit:

It seems that this 4kB limitation isn’t such a hindrance after all and it takes a good number of local variables (4,045) within the fiber itself to cause a SystemStackError to be raised.

count = 0
loop do
  count += 1
  puts count
  varlist = String.new
  count.times do |i|
    varlist += "a#{i} = 1\n"
  end
  s = "fiber = Fiber.new do \n #{varlist} \n end \n fiber.resume"
  eval(s)
end

Not the most elegant code but it does seem to demonstrate the limitations of a fiber’s stack. It seems as though it’s only return values, local variables (all of which contain a reference to an object on the heap) and method calls get put on the stack. I haven’t tested whether the local variables etc in methods that are called from a fiber are part of the fiber’s stack.

Edit 2:

Modified the above code. It does appear that variables etc in called methods become part of the fiber’s stack. If this is the case, then the call depth (even without recursion) could be more of an issue as methods themselves are likely to require more space on the stack than variables (which seem to be transparent references to objects on the heap).

The following code fails on the 4,031st iteration and indicates variables in called methods become part of the fiber’s stack:

count = 0
loop do
  count += 1
  puts count
  varlist = String.new
  count.times do |i|
    varlist += "a#{i} = 1\n"
  end
  m = "def meth\n #{varlist} \n end"
  eval(m)
  fiber = Fiber.new do
    meth
  end
  fiber.resume
end

Edit 3:

Just tried running the initial code example on Rubinius 2.0. Its fibers don’t seem to have a 4kB stack limit, although beyond about 3,500th iteration it becomes increasingly and noticeably slow, and at around the 5,000th iteration it’s averaging about one iteration a second. I don’t know if there is a limit with RBX because I quit execution at just over 5,100 iterations. RBX is also using several times more memory than MRI 1.9.3.

JRuby 1.7 also doesn’t seem to have a 4kB stack size for fibers and if fibers have a max stack size it’s unknown to me. I completed 5,000 iterations of the first code example without problems, although as can be expected, the JVM chewed through a few hundred MB of RAM.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:26:38+00:00Added an answer on June 15, 2026 at 6:26 am

    The consequences of that are that you must pay more attention to the memory of your Fiber code, because you might have memory leaking.

    Some recursive functions might give you problems

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For Fibers we have got classic example: generating of Fibonacci numbers fib = Fiber.new
What I have read from MSDN , Each new thread or fiber receives its
We need to write software that would continuously (i.e. new data is sent as
http://fiber.google.com/how/ Is that all HTML5 canvas animation? Flash? I have a hard time telling.
The em-synchrony documentation links to this article which implies that this code with fiber:
I'm working on a native fiber/coroutine implementation – fairly standard, for each fiber, a
What is the difference between a thread and a fiber? I've heard of fibers
I've been studying fibers in Ruby, and the term semicoroutine has come up. What
How do I utilize fibers best in my game code? Should it only be
I have simple script with EventMachine, Fibers and faye require faye require em-synchrony require

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.