PDA

View Full Version : Extremely inefficient update of SVG text sprites



stahlman
4 Oct 2011, 12:17 PM
Our application uses a significant number of draw components. After noticing what appeared to excessive sluggishness in both initial draw and subsequent updates, I began to look more closely at what was happening. For SVG, the problem appears to be caused by the unconditional call to tuneText, which occurs every time setAttributes is invoked on a text sprite, regardless of whether the text is actually changing! Apparently, tuneText performs 2 tasks: 1) wrap lines of text in separate tspans; 2) adjust tspans' dy parameter, not only to accomplish line-wrapping, but also to ensure that the y coordinate reference for both SVG and VML reference is the vertical center of the text box. To accomplish the second objective, Ext needs to know the bounding box of the text, which it obtains by a call to getBBoxText, which attempts to get the bbox by calling getBBox on the dom element (falling back on calls to getExtentOfChar() on individual chars if getBBox fails). The call to getBBox is pretty costly, especially when you're updating sprites within slider drag event handlers (as I am). I can only imagine how costly it would be if I were running a version of Firefox that required the fallback to a separate getExtentOfChar() for each character...

The real question is, why is tuneText called at all when the sprite's text is not changing. Given that tuneText accomplishes line wrapping with "dy" rather than "y" attribute, I'm thinking it's probably unnecessary even when the text sprite's y coordinate is changing.