# \[Feature:1.9\] speed up continuation in 1.9

**URL:** <https://www.ruby-forum.com/t/feature-1-9-speed-up-continuation-in-1-9/153465>\
**Category:** Development\
**Created:** [November 17, 2008, 4:49pm UTC](https://www.ruby-forum.com/t/feature-1-9-speed-up-continuation-in-1-9/153465 "2008-11-17T16:49:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yusuke\_ENDOH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/c89c15/32.png) [@Yusuke\_ENDOH](https://www.ruby-forum.com/u/Yusuke_ENDOH)\
**Post date:** [November 17, 2008, 4:49pm UTC](https://www.ruby-forum.com/t/feature-1-9-speed-up-continuation-in-1-9/153465/1 "2008-11-17T16:49:07Z")

</div>

e$B1sF#$G$9!#e(B

1.9 e$B$N7QB3$Oe(B 1.8 e$B$KHf$Y$F6KC\<$KCY$$$h$&$G$9!#e(B

$ time ruby18 -e ‘i = 0; callcc {|c| $c = c }; i += 1; $c.call if i \<  
1000000’  
real 0m1.060s  
user 0m1.050s  
sys 0m0.010s

$ time ruby19 -rcontinuation -e ‘i = 0; callcc {|c| $c = c }; i += 1;  
$c.call if i \< 1000000’  
real 1m57.022s  
user 1m56.780s  
sys 0m0.180s

capture e$B$de(B call e$B$N:]!"e(BVM  
e$B$N%9%?%C%/$r\>o$K4]$4$H%3%T!\<$7$F$$$k$N$,e(B  
e$B860x$G!"I,MW$J$H$3$me(B (e$B@hF,$Ne(B sp e$BItJ,$H=\*C\<$Ne(B cfp  
e$BItJ,e(B) e$B$@$1%3%T!\<e(B  
e$B$9$k$h$&$K$7$?$i!"e(B1.8 e$BJB$KB.$/$J$j$^$7$?!#e(B

$ time ./ruby.fast-cont -rcontinuation -e ‘i = 0; callcc {|c| $c = c  
}; i += 1; $c.call if i \< 1000000’

real 0m0.660s  
user 0m0.660s  
sys 0m0.000s

e$B;d$N4D6-$Ge(B test-all e$B$,DL$k$3$H$O3NG’$7$F$$$^$9!#e(B  
e$B$H$/$K0[O@$,$J$1$l$P%3%\_%C%H$7$h$&$H;W$$$^$9!#e(B

# Index: cont.c

— cont.c (revision 20241)  
+++ cont.c (working copy)  
@@ -14,6 +14,8 @@  
#include “gc.h”  
#include “eval\_intern.h”

+#define CAPTURE\_JUST\_VALID\_VM\_STACK 1  
+  
enum context\_type {  
CONTINUATION\_CONTEXT = 0,  
FIBER\_CONTEXT = 1,  
@@ -25,6 +27,10 @@  
VALUE self;  
VALUE value;  
VALUE \*vm\_stack;  
+#ifdef CAPTURE\_JUST\_VALID\_VM\_STACK

- int vm\_stack\_slen; /\* length of stack (head of th-\>stack) \*/
- int vm\_stack\_clen; /\* length of control frames (tail of th-\>stack)  
\*/  
+#endif  
VALUE \*machine\_stack;  
VALUE \*machine\_stack\_src;  
#ifdef \_\_ia64  
@@ -75,8 +81,13 @@  
rb\_thread\_mark(&cont-\>saved\_thread);

if (cont-\>vm\_stack) {  
+#ifdef CAPTURE\_JUST\_VALID\_VM\_STACK  
rb\_gc\_mark\_locations(cont-\>vm\_stack,

- 

```
    cont->vm_stack + cont->saved_thread.stack_size);

```

- 

```
    cont->vm_stack + cont->vm_stack_slen + cont->vm_stack_clen);

```

+#elif

- 

```
 rb_gc_mark_localtion(cont->vm_stack,

```

- 

```
    cont->vm_stack, cont->saved_thread.stack_size);

```

+#endif  
}

if (cont-\>machine\_stack) {  
@@ -247,8 +258,16 @@  
contval = cont-\>self;  
sth = &cont-\>saved\_thread;

+#ifdef CAPTURE\_JUST\_VALID\_VM\_STACK

- cont-\>vm\_stack\_slen = th-\>cfp-\>sp + th-\>mark\_stack\_len - th-\>stack;

- cont-\>vm\_stack\_clen = th-\>stack + th-\>stack\_size - (VALUE\*)th-\>cfp;

- cont-\>vm\_stack = ALLOC\_N(VALUE, cont-\>vm\_stack\_slen +  
cont-\>vm\_stack\_clen);

- MEMCPY(cont-\>vm\_stack, th-\>stack, VALUE, cont-\>vm\_stack\_slen);

- MEMCPY(cont-\>vm\_stack + cont-\>vm\_stack\_slen, (VALUE\*)th-\>cfp,  
VALUE, cont-\>vm\_stack\_clen);  
+#elif  
cont-\>vm\_stack = ALLOC\_N(VALUE, th-\>stack\_size);  
MEMCPY(cont-\>vm\_stack, th-\>stack, VALUE, th-\>stack\_size);  
+#endif  
sth-\>stack = 0;

- MEMCPY(th-\>stack, cont-\>vm\_stack, VALUE, cont-\>vm\_stack\_slen);

- MEMCPY(th-\>stack + sth-\>stack\_size - cont-\>vm\_stack\_clen,

- 

```
    cont->vm_stack + cont->vm_stack_slen, VALUE, 

```

cont-\>vm\_stack\_clen);  
+#elif  
MEMCPY(th-\>stack, cont-\>vm\_stack, VALUE, sth-\>stack\_size);  
+#endif  
}  
else {  
/\* fiber \*/

---

<div class="post-metadata">

**Author:** ![Yusuke\_ENDOH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/c89c15/32.png) [@Yusuke\_ENDOH](https://www.ruby-forum.com/u/Yusuke_ENDOH)\
**Post date:** [November 18, 2008, 12:46am UTC](https://www.ruby-forum.com/t/feature-1-9-speed-up-continuation-in-1-9/153465/2 "2008-11-18T00:46:02Z")

</div>

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:37106] [Feature:1.9] speed up continuation in  
1.9”  
on Tue, 18 Nov 2008 00:44:53 +0900, “Yusuke ENDOH” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
writes:

|1.9 e$B$N7QB3$Oe(B 1.8 e$B$KHf$Y$F6KC\<$KCY$$$h$&$G$9!#e(B

|capture e$B$de(B call e$B$N:]!"e(BVM e$B$N%9%?%C%/$r\>o$K4]$4$H%3%T!\<$7$F$$$k$N$,e(B  
|e$B860x$G!"I,MW$J$H$3$me(B (e$B@hF,$Ne(B sp e$BItJ,$H=\*C\<$Ne(B cfp e$BItJ,e(B) e$B$@$1%3%T!\<e(B  
|e$B$9$k$h$&$K$7$?$i!"e(B1.8 e$BJB$KB.$/$J$j$^$7$?!#e(B

|e$B;d$N4D6-$Ge(B test-all e$B$,DL$k$3$H$O3NG’$7$F$$$^$9!#e(B  
|e$B$H$/$K0[O@$,$J$1$l$P%3%\_%C%H$7$h$&$H;W$$$^$9!#e(B

e$B$$$$$s$8$c$J$$$G$7$g$&$+!#e(B

---

<div class="post-metadata">

**Author:** ![Yusuke\_ENDOH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/c89c15/32.png) [@Yusuke\_ENDOH](https://www.ruby-forum.com/u/Yusuke_ENDOH)\
**Post date:** [November 18, 2008, 5:28pm UTC](https://www.ruby-forum.com/t/feature-1-9-speed-up-continuation-in-1-9/153465/3 "2008-11-18T17:28:00Z")

</div>

e$B%A%1%C%He(B #758 e$B$,99?7$5$l$^$7$?!#e(B (by Yusuke E.)

e$B%9%F!\<%?%9e(B Opene$B$+$ie(BClosede$B$KJQ99e(B  
e$B?JD=e(B % 0e$B$+$ie(B100e$B$KJQ99e(B

## Applied in changeset r20256.

[http://redmine.ruby-lang.org/issues/show/758](http://redmine.ruby-lang.org/issues/show/758)
