I have a method, which connects to a HTTP server and requests via XMLRPC, a list of data structures and then for each data structure gets a list of attributes and the values of those attributes. It’s implemented using nested for each loops.
The problem is that it’s loading a lot of data all at once, and consuming a massive amount of CPU (over 100%) reading responses from the server and parsing the XML.
If I were writing the program in C, I’d insert a usleep() at the end of the loop, to wait before trying to load more data and reduce CPU usage. What would the equivalent be in Flex?
One of the biggest drawbacks of flash/flex is that the generated application is single threaded, so running CPU intensive tasks like parsing large responses will make the application freeze.
Some of the solutions I use to work around those problems are:
If possible do not load everything from the server at once but load it through multiple calls (i.e read your data using 10 pages of 50 results instead of 500 at once).
Make sure that the data you are loading is not directly binded on some UI elements (changes in the data will trigger change on the UI that will consume more CPU)
Also returning XML results is not the most efficient way (using RemoteObjects through BlazeDs is more efficient as it uses binary streams instead of strings).