Closed samreid closed 11 years ago
I added instrumentation that lets you track when certain objects are allocated. When animating the object to the right at full speed on the motion screen of Forces and Motion: Basics, there are 40 Vector, 23 Matrix and 61 Bounds allocated per frame, spread across 75 distinct code paths, most of which are being triggered from common code libraries, like scenery and dot. I experimented with object pooling to recycle objects after they are used, but I tried to apply this systemically, and ran into serious problems because every time a pooled object is created it must be carefully tracked and recycled or you create a memory leak and worse performance problems. So I think we could (a) investigate ways to speed up some of the more common of the 75 code paths without object allocations or (b) just apply the pooling pattern to isolated scenarios instead of across the board or (c) invest in applying object pooling systemically. In my opinion, (c) could take 2+ months to get it done but would be very low memory and would make all of our subsequent code more complex. With (b), there is lots of additional overhead associated with pooling: you have to keep track of whether the object is alive or dead which means extra memory and/or processor time, and additional code complexity to apply the pattern and make sure there are no leaks. I don't yet know if it will slow down the application or not, or if it would solve the "pausing" problem. I did not investigate Continuation Passing Style, which would be a radically different design approach for us, if it solves the problem at all without creating worse problems.
I moved these notes to #110 and will close this ticket.
Simulation pauses briefly every few seconds on the iPad, tested with Forces and Motion: Basics. http://www.colorado.edu/physics/phet/dev/html/forces-and-motion-basics/1.0.0-rc8/forces-and-motion-basics.html It appears to be garbage collection. I also see a sawtooth pattern with a period of about 3-4 seconds when running in Win8/Chrome.