Bug 1793 - Application very slow, consuming all of the CPU even when paused
Application very slow, consuming all of the CPU even when paused
Status: CLOSED FIXED
Product: electric
Classification: Unclassified
Component: Other/Unknown
1
All All
: P1 blocker
: ---
Assigned To: developers
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-04-15 05:43 UTC by strubin
Modified: 2011-04-15 21:25 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description strubin 2011-04-15 05:43:42 UTC
** ORIGINALLY POSTED BY Kelly Kishore on 2008-03-10 20:11:43 **

Whenever a content file is playing, the application is running very slow.  The CPU seems to be fully utilized with 0% idle and mostly in user space ~97% for any resolution of video content (CIF, 480, 720, etc.)  Suspicion from previous observations point to the repaint()/paintComponent() to be the culprit.  Seems like it repainting unnecessarily even when there is no motion.
Comment 1 strubin 2011-04-15 15:20:24 UTC
** ORIGINALLY POSTED BY Kelly Kishore on 2008-03-26 09:09:21 **

This is being escalated to the highest priority as the CPU utilization of the application consumes the entire system and makes both the application and system unusable.  Since this was narrowed to the paintComponent() method through the profiler, limiting the unnecessary rendering should alleviate this problem.  For more information and background on this, please refer to the article:

http://java.sun.com/products/jfc/tsc/articles/painting/index.html#smart
Comment 2 strubin 2011-04-15 15:20:27 UTC
** ORIGINALLY POSTED BY Kelly Kishore on 2008-03-27 18:06:10 **

System.gc() are being called explicitly in the mediaLib libraries and the removal of them provides some level of increase in the frame rate.  However, this does not resolve the problem where the CPU is still being consumed when no video is visible.  

In previous versions of the java vm (pre 1.2), this was commonly used by developers in the past; however, this is no longer necessary.  Unsure of the original reason.

Test results:

********************************
with explicit System.gc() calls:
********************************
CIFp5994_shields_ter-crop-offset.yuv  (352x288 with 0 delay)
$ java -cp yuv420play.jar yuv420play4

number of frames = 604 (frames)
real speed       = 6.420204 (fps)
display speed    = 19.958364 (fps)


foreman.qcif (176x144 with 0 delay)
$ java -cp yuv420play.jar yuv420play4

number of frames = 400 (frames)
real speed       = 11.578429 (fps)
display speed    = 23.457659 (fps)


************************************
without explicit System.gc() calls:
************************************
CIFp5994_shields_ter-crop-offset.yuv  (352x288 with 0 delay)
$ java -cp yuv420play.jar yuv420play4

number of frames = 604 (frames)
real speed       = 63.472042 (fps)
display speed    = 514.91895 (fps)


foreman.qcif (176x144 with 0 delay)
$ java -cp yuv420play.jar yuv420play4

number of frames = 400 (frames)
real speed       = 232.6934 (fps)
display speed    = 793.65076 (fps)
Comment 3 strubin 2011-04-15 15:20:30 UTC
** ORIGINALLY POSTED BY Preeti on 2008-04-02 12:29:53 **

The medialibImageJPanel's paint component has called drawImage method which calls an image observer recursively even when no video is being played.Profiler also showed that paintComponent was invoked many times when there was no video playing. Removing the repeated calls to the image observer in the drawImage method shows the CPU usage has gone to down to 1% when its not playing any video and the video is paused. The profiler now shows that paintComponent is invoked just once when there is no video.
The speed also has an impact of resolving this.

********************
with image observer
********************

number of frames = 504 (frames)
real speed       = 12.24222 (fps)
display speed    = 33.443928 (fps)

**********************
without image observer
**********************

number of frames = 504 (frames)
real speed       = 16.78154 (fps)
display speed    = 44.807964 (fps)
Comment 4 strubin 2011-04-15 15:20:33 UTC
** ORIGINALLY POSTED BY Preeti on 2008-04-02 13:46:15 **

I used the yuv file:

480p5994_shields_ter-crop.yuv(720x480 with delay 0)

The results are taken on a slow machine with recent changes in the code.