6 Replies Latest reply on Jun 2, 2010 5:29 PM by 843807

    occasional "lag" in drawImage

    843807
      Hi,

      my problem is, that sometimes the drawImage function needs way more time than it should. It only seems to happen at my computer which makes this hard to troubleshoot. So far the problem has not occured anywhere else.

      I'm simply drawing small tile images (64x48) in a JPanel's paintComponent. After adding a TimeMeasurement this is what the code looks like:
      TimeMeasurement drawImage=new TimeMeasurement("drawImage");
      g.drawImage(tile, xDrawAt, yDrawAt, null);
      drawImage.end();
      The result of the TimeMeasurement is this:
        drawImage: 0ms
        drawImage: 0ms
        drawImage: 0ms
        drawImage: 0ms
        drawImage: 16ms
        drawImage: 0ms
        drawImage: 0ms
        drawImage: 0ms
        drawImage: 0ms
        drawImage: 0ms
        drawImage: 0ms
        drawImage: 0ms
        drawImage: 0ms
        drawImage: 0ms
        drawImage: 0ms
        drawImage: 0ms
        drawImage: 0ms
        drawImage: 0ms
        drawImage: 16ms
        drawImage: 15ms
        drawImage: 16ms
        drawImage: 0ms
        drawImage: 0ms
        drawImage: 0ms
        drawImage: 0ms
      As you see it just sometimes takes 16ms while it generally takes 0ms, without any pattern. The images are all similar (pre-loaded subparts of a bigger one) and as I've mentioned before this only happens on my PC (which is a lot more powerful than others on which it runs smoothly).

      I have Java 6 on Windows XP. I could go more into details here if necessary.

      I realise that this might be a hard question to answer but I'm pretty clueless about what's causing this, so any ideas would help.

      regards lukar
        • 1. Re: occasional "lag" in drawImage
          843807
          During this lag, is there IO going on? If you want to check just the drawImage load a several (or all) of the images you are using and rotate through them, this will give you an idea if you are having some display problem.

          More likely you are hitting some Windows virtual memory action, System blocking due to IO, or the Java GC--btw, due to the patter you show, I would not expect the Java GC.
          • 2. Re: occasional "lag" in drawImage
            843807
            I tried drawing just one image but it didn't really change anything. (it were only 3 different images to start with)
            Memory usage is only at about 30MB, however the CPU usage is close to 100%.

            Do you know any way to test if it is a problem with Windows virtual memory?

            edit: what also confused me is the fact that the javadoc of drawImage says the function returns imediately.Doesn't that mean that there should be almost no wait at all?

            Edited by: D3fe4t on Jun 1, 2010 8:19 AM
            • 3. Re: occasional "lag" in drawImage
              darrylburke
              The granularity of System.currentTimeMillis() on Windows is around 16 ms. That explains your results.

              db
              • 4. Re: occasional "lag" in drawImage
                843807
                So that means, that the time is not in fact 0ms or sometimes 16ms but rather somewhere inbetween and Date().getTime() simply doesnt use the exact time in windows.

                So I'm still stuck with my performance problem but at least it's a little less weird...
                • 5. Re: occasional "lag" in drawImage
                  843807
                  You can try System.nanoTime(), just remember a nanosecond is about as long as it takes electricity to travel 1 foot--it's not a significant time for measuring most events, but 1,000,000 nanoseconds is equal to 1 millisecond.
                  • 6. Re: occasional "lag" in drawImage
                    843807
                    Yeah, I'm using a more accurate measurement system now and the time required was pretty constant.

                    I tried installing installing new graphic drivers and surprisingly it helped. The program now runs a lot smoother although i had the ati driver from last june until now, which shouldn't be that bad. There might also have been some special problem with the drivers.

                    Anyway it works now so thanks everybody!