Suggestions for increased performance and better memory utilization for FTE
We all know that there is a pretty big downside to creating potentially thousands of DisplayObjectContainers (TextLines).
o - they are slow to create
o - they may be short lived
o - they occupy lots of memory
o - they may need to be generated frequently
Currently, there is only one way to find out all the information you need and that is to create all the TextLines for a given data set.
This means that FTE does not scale well. It becomes very slow for large data sets that need to be regenerated.
I am proposing a possible solution and hope that Adobe will consider it.
If we had the right tools we could create a sliding window of display objects. With large data sets only a fraction of the content is actually visible. So only the objects that are actually visible need to be created. There is no way to do this efficiently with FTE at the present time.
So we need a few new methods and classes that parallel what you already have.
New Method 1)
TextBlock.getTextLineInfo (width:Number, lineOffset:Number, fitSomething:Boolean) : TextLineInfo
This method returns simple information about all the lines in a text block. No display objects are generated.
class TextLineInfo
{
public var maxWidth:Number; // maximum width of all the textlines in the textBlock
public var totalHeight:Number; // totalHeight of all the textlines in the textBlock
public var numLines:int; // number of lines in the lineInfo Array
public var lineInfo:Array; // array of LineInfo items for each textline
}
class LineInfo // sample - more or less may be needed
{
public var rawTextLength:int;
public var textWidth:Number;
public var textHeight:Number;
public var ascent;
public var descent;
public var textBlockBeginIndex:int;
}
Now getTextLineInfo needs to be as fast as possible. Find an advanced game programmer to optimize, write it in assembler, put grease on it.... do whatever it takes to make it fast.
New Method 2)
TextBlock.createTextLines (textLineInfo:TextLineInfo, begIdx:int, endIdx:int) : Array
Creates and returns an Array of TextLine objects based on the previously created TextLineInfo. A range can be specified.
It should be obvious that the above functions will improve the situation. Since this parallels what you already have it should not be earth shaking to implement.
New Display Object type
Much of the time you do not need a full blown Display Object Container for a TextLine. I suggest an additional lightweight TextLine class. A good parallel would be similiar to the difference between Sprite and Shape.
Now I have some done some testing with this idea. Since you cannot implement this fully as it stands, I had to make some concessions. This sample contains 100,004 characters of data. You can resize it and it will always be fast. This sample only creates the visible portion of the display, but you may scroll into view the invisible portions. Each time the page is resized, it will jump back to the top, because of the limitations of FTE currently.
The sample also contains a caret and allows the selection of an area but no editng, copy, paste etc., is available for this test.
If I did not do special handling for this, it would lock up for sure and be very user unfreindly.
Now it takes a moment to load 100k into the TextElement.so there may be a pause before you see that data. I may need to improve this. Once loaded it performs quite well.
Without the above or similiar optimizations. FTE is just not going to scale up very well at all.
Don
