title: Python on android (kivy) - speed bottlenecks for certain operations?
body: <p>I'm fairly far along developing a Kivy app. Its targeted for android, but will also work (simultaneously with a different skin) on desktops and hopefully iOs eventually.</p>
  
  <p>The basic dependencies I'm heavily using are:-</p>
  
  <ul>
  <li><p>twisted - using this as an IPC, my app has a server/client
  relationship   between the data manipulation and the UI</p></li>
  <li><p>Whoosh - for text search</p></li>
  <li><p>xmltodict - for easy XML manipulation</p></li>
  </ul>
  
  <p>I'm having REALLY long app startup times on android, on a relatively recent phone, which doesn't bode well. From my rough timings (based on time.time() and subtracting from my App's <strong>init</strong> time):-</p>
  
  <ul>
  <li><p>My app gets control from kivy startup at about 1 second in</p></li>
  <li><p>My initialization of custom classes etc. is done at the 2.4 second mark</p></li>
  <li><p>At the 14.4 second mark, I finally complete the bulk of my data loading</p></li>
  <li><p>At the 17 second mark, I start sending the data out to the client UI using twisted</p></li>
  <li><p>At the 22 second mark, the UI receives the data</p></li>
  </ul>
  
  <p>There's multiple points I want to address there. For example the roughly 5 second gap for data send can be easily broken into pieces and updated in the UI piecemeal, so I'm keeping that for later, but I need to ask about the long 12 second gap for data loading. This data loading involves creating about a 1000 instances of a custom class, with the following steps (cumulative time over 1000 instances):-</p>
  
  <ul>
  <li><p>Reading data from 1000 text XML files (0.734 seconds)</p></li>
  <li><p>Parsing the XML in the read data (9.198 seconds)</p></li>
  <li><p>Filling the object's variables based on the parsed XML (0.585 seconds)</p></li>
  <li><p>Directory tree traversal (use this to locate a certain base folder, 0.0824 seconds)</p></li>
  <li><p>mtime measurement for the xml files (0.12 seconds)</p></li>
  </ul>
  
  <p>The measured timings surprised me, because the equivalent timings for running the same code on my laptop are 0.041, 0.9, 0.062, 0.009, and 0.016). Everything's about 10 times slower.</p>
  
  <p>What, if anything, can I do about this? The phone being used for testing has 3GB of RAM and a Snapdragon 801 processor, so I'm quite worried about using this app on slower/older models. My initial thoughts were that the slow-down was due to sd cards being inherently slower than my laptop's hard disk drive, but the fact that xml parsing (non IO related) took so long seems to indicate processing problems.</p>
  
  <p>Suggestions/criticisms welcome.</p>