Problems with recursion

59 views
Skip to first unread message

Jason Durham

unread,
Aug 4, 2016, 4:18:08 PM8/4/16
to Lucee
We're in the process of tooling up to roll out Lucee 4.5.3 to production with code that is currently running on ACF8.  We have a couple of areas in our application where we use recursion and Lucee appears to be having a tough time with a method calling itself.  I created a test bit of code to demonstrate the issue.  You can run this on CFLive.net for both ACF and Lucee and you'll notice ACF doesn't hiccup while Lucee throws a stack overflow. Is there an issue in my code?  If not, is this a known bug?

<cfscript>

variables.times = 10;

function recurse( source, stop) {

out = [source];
if(variables.times > 0) {
variables.times--;
arrayAppend(out, recurse(out, true));
}
return out;
};

source = [1];
start = getTickCount();
result = recurse(source, false);
end = getTickCount();

</cfscript>

<cfdump var="#result#" />
<cfdump var="#end-start# ms" />

Jason Durham

unread,
Aug 4, 2016, 5:59:48 PM8/4/16
to lu...@googlegroups.com
I've attached a cleaner version of the code snippet.  This works on ACF8, ACF10, ACF11, ACF16 and times out on Railo 4.2, Lucee 4.5 or Lucee 5.

<cfscript>

times = 10;

function recurse( source ) {
        var out = source;
if(times > 0) {
times--;
arrayAppend(out, recurse(out));
}
return out;
};

source = [1];
start = getTickCount();
result = recurse(source);
end = getTickCount();

</cfscript>

<cfdump var="#result#" />
<cfdump var="#end-start# ms" />

Jason Durham

--
Get 10% off of the regular price for this years CFCamp in Munich, Germany (Oct. 20th & 21st) with the Lucee discount code Lucee@cfcamp. 189€ instead of 210€. Visit https://ti.to/cfcamp/cfcamp-2016/discount/Lucee@cfcamp
---
You received this message because you are subscribed to a topic in the Google Groups "Lucee" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lucee/2UXKYCzmnpQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lucee+unsubscribe@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/6761290b-f585-436a-9169-8829786b2ff9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jon Clausen

unread,
Aug 4, 2016, 6:36:10 PM8/4/16
to lu...@googlegroups.com

Jason,

It’s probably an issue with concurrent modifications to the reference object. Lucee is strict about array references. If you use duplicate on the source argument the loop completes just fine in Lucee:

<cfscript>
times = 10;

function recurse( source ) {
    var out = duplicate(source);
    if(times > 0) {
        times--;
        arrayAppend(out, recurse(out));
    }
    return out;
};

source = [1];
start = getTickCount();
result = recurse(source);
end = getTickCount();

writeDump(var=result);
writeDump("#end-start# ms");
abort;

</cfscript>

Jason Durham

unread,
Aug 4, 2016, 8:12:45 PM8/4/16
to lu...@googlegroups.com
Thanks Jon.  Brad Wood told me that moments before you sent this and I was coming here to share it when my doorbell rang. 


Jason Durham

--
Get 10% off of the regular price for this years CFCamp in Munich, Germany (Oct. 20th & 21st) with the Lucee discount code Lucee@cfcamp. 189€ instead of 210€. Visit https://ti.to/cfcamp/cfcamp-2016/discount/Lucee@cfcamp
---
You received this message because you are subscribed to a topic in the Google Groups "Lucee" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lucee/2UXKYCzmnpQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lucee+unsubscribe@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Jason Durham
Reply all
Reply to author
Forward
0 new messages