Grow the call frame array dynamically.

Previously, fibers had a hard-coded limit to how big their stack size
is. This limit exists in two forms: the number of distinct call frames
(basically the maximum call depth), and the number of unique stack
slots.

This fixes the first half of this by dynamically allocating the call
frame array and growing it as needed. This makes new fibers smallers
since they can start with a very small array. Checking and growing as
needed doesn't noticeably regress the perf on the other benchmarks, and
it makes a new fiber benchmark about 45% faster.

The stack array is still hardcoded, but that will be in another commit.
This commit is contained in:
Bob Nystrom
2015-07-01 00:00:25 -07:00
parent 18dcd3ce3d
commit 2387d4dc31
5 changed files with 82 additions and 36 deletions
+16
View File
@@ -0,0 +1,16 @@
// Creates 10000 fibers. Each one calls the next in a chain until the last.
var fibers = []
var sum = 0
var start = IO.clock
for (i in 0...100000) {
fibers.add(new Fiber {
sum = sum + i
if (i < 99999) fibers[i + 1].call()
})
}
fibers[0].call()
IO.print(sum)
IO.print("elapsed: ", IO.clock - start)