Skip to main content
JoãoCésar17023019
Community Expert
Community Expert
August 14, 2017
Question

Function trace() is delaying movie output

  • August 14, 2017
  • 3 replies
  • 516 views

Hi again!

Is it just me or the trace() function is severely delaying movie output? I'm quite sure it did not used to be like this.

In this simple example, the output will be immediate:

var i:int, total:int = 999, count:int = 0;

for (i = 0; i < total; i++)

     count++;

But if you include a trace statement, at least in my case, the output will be delayed for about 5 seconds.

var i:int, total:int = 999, count:int = 0;

for (i = 0; i < total; i++)

{

     count++;

     trace(count);

}

For each situation I'm coding a game or app that I need a trace statement inside a loop a huge delaying is happening.

Can someone clarify this?

Thanks!

This topic has been closed for replies.

3 replies

JoãoCésar17023019
Community Expert
Community Expert
August 14, 2017

Thanks, RandomlyFish.

But, as discussed above, this doesn't seem to be a matter of AS3 optimization. I can tell you because I've already wrote a lot of way heavier code using not only one but several trace statements and the difference wasn't noticeable on my machines/OS.

But now, the output is taking around 5 seconds on a simple loop.

And even Colin said he saw a difference between Mac and Windows. So, if it was something related to AS3, in both scenarios the SWF should be exported in about the same time. Even if there was some difference, it should be of just a few miliseconds.

Inspiring
August 14, 2017

Yep, using trace a lot slows it down significantly, no matter what you decide to trace. I remember it also being an issue in the Unity editor, last time I used it.

You could try storring each thing you want to trace in an array, and then trace everything with one trace call. Or you could create your own console that's inside the animation.

Colin Holgate
Inspiring
August 14, 2017

If I do:

var i:int, total:int = 999, count:int = 0;

for (i = 0; i < total; i++){

     count++;

}

trace(count);

or:

var i:int, total:int = 999, count:int = 0;

for (i = 0; i < total; i++){

     count++;

     trace(count);

}

the Output window appears immediately, with either a list ending in 999, or just 999.

I don't know why it would be different for you.

JoãoCésar17023019
Community Expert
Community Expert
August 14, 2017

Hi! Thanks for the answer.

The problem does happen to me.

Here is a very short video of my situation:

I hope it helps clarifying what is going on.

Colin Holgate
Inspiring
August 14, 2017

It's the time for the SWF to appear that is longer for you. For me both cases work within a second.

That's on Mac. In Windows 10 I can see the difference in time. I think that the script is finishing before the window appears, which is odd, and it does mean that the trace statements are taking a significant time.

Trace uses Strings, and during playback it's converting an int to a String 999 times. There's some overhead for the playback to figure out that the variable is something that can be converted to a String. I don't know why that is slow on Windows and fast on Mac, but you can reduce the delay a lot by telling the compiler what you have in mind. Try timing this version:

var i:int, total:int = 999, count:int = 0;

for (i = 0; i < total; i++){

     count++;

     trace(String(count));

}