dconsole icon indicating copy to clipboard operation
dconsole copied to clipboard

Problems in recursive functions

Open larsiusprime opened this issue 10 years ago • 1 comments

I really like the profiler, but it seems to have trouble with codebases that have a lot of recursion (like Flixel-UI's _loadThing() function).

For instance:

function foo(iteration:Int = 0):Void
{
    DC.beginProfile("foo");
    if (iteration < 10)
    {
        foo(iteration++);
    }
    DC.endProfile("foo");
}

Call foo() from your code, and you will receive the error "foo already started." The problem is sometimes I want to be able to profile a recursive function but there's no easy way to do that if the profiler will throw an error if I begin another foo profile before I finish the last one.

If I do something like this:

private function foo(iteration:Int = 0):Void
{
    DC.beginProfile("foo:"+iteration);
    if (iteration < 10)
    {
        foo(iteration+1);
    }
    DC.endProfile("foo:"+iteration);
}

I can get around it, but it would be handy if the profiler would handle this case internally; it's a pretty common use-case.

larsiusprime avatar Aug 15 '14 18:08 larsiusprime

I ran into the same problem very quickly using the profiler, I'll have a look soon.

tiagolr avatar Aug 17 '14 20:08 tiagolr