Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
HTML5 canvas: Performance on context access.
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
davidcm  
View profile  
 More options Jan 18 2010, 7:38 am
Newsgroups: mozilla.dev.performance
From: davidcm <david.canadas.m...@gmail.com>
Date: Mon, 18 Jan 2010 04:38:46 -0800 (PST)
Local: Mon, Jan 18 2010 7:38 am
Subject: HTML5 canvas: Performance on context access.
Hi,
I've found some quite of strange behavior when updating the canvas
inside a loop. First canvas access after a screen update (e.g., when
the CPU gets idle) has an extremely high cost, even if just putting a
pixel onto the screen. An example that shows this behavior is below,
you can profile consumed timings with the Firebug profiler. In the
code I'm working right now, first access takes the 23% of the loop
time, and the update of about 50 images -with slicing, rotations, etc-
just take a 15%).

I don't know if this is the standard behavior, If this is the
performance supposed to be by some kind of limitation in the standard
or whatsoever, I just want to know what this happens and how to avoid
it if possible (I'm working on time-critical applications for small
devices and I need to improve performance on that).

Thank you.

-- Example start --

<html>
<body>
<canvas id="myCanvas"/>
<script type="text/javascript">
var canvas = document.getElementById('myCanvas'), context =
canvas.getContext('2d');
function f1() {
  context.fillStyle = 'red';
  context.fillRect(0, 0, 1, 1);

}

function f2() {
  context.fillStyle = 'blue';
  for(var i = 0; i < 10; i++) context.fillRect(Math.random() * 100,
Math.random() * 100, Math.random() * 100,
    Math.random() * 100);
}

setInterval(function() {
  f1();
  f2();
}, 100);

</script>
</body>
</html>

-- Example end --

Check the performance of this example with the firebug profiler; you
will see that f1() takes more time to run that f2()... and


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Boris Zbarsky  
View profile  
 More options Jan 19 2010, 1:06 am
Newsgroups: mozilla.dev.performance
From: Boris Zbarsky <bzbar...@mit.edu>
Date: Tue, 19 Jan 2010 01:06:15 -0500
Local: Tues, Jan 19 2010 1:06 am
Subject: Re: HTML5 canvas: Performance on context access.
On 1/18/10 7:38 AM, davidcm wrote:

> I've found some quite of strange behavior when updating the canvas
> inside a loop. First canvas access after a screen update (e.g., when
> the CPU gets idle) has an extremely high cost, even if just putting a
> pixel onto the screen. An example that shows this behavior is below,
> you can profile consumed timings with the Firebug profiler. In the
> code I'm working right now, first access takes the 23% of the loop
> time, and the update of about 50 images -with slicing, rotations, etc-
> just take a 15%).

I'd be interested in seeing your actual loop...  As well as which OS
you're on and what Gecko version.  I just tried your testcase on Mac
with a mozilla-central build, and the multiple fills take more time than
the one fill, as expected...

> Check the performance of this example with the firebug profiler; you
> will see that f1() takes more time to run that f2()... and

Note that the firebug profiler perturbs the results enough (e.g. by
disabling the jit when active) that its information may or may not match
what you're doing well.

Do timings using JS Date() show the same effect?

-Boris


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »