Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8189349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:15:02+00:00 2026-06-07T03:15:02+00:00

Recently, I study HTML Canvas using Google Closure. but the performance of Google Closure

  • 0

Recently, I study HTML Canvas using Google Closure.

but the performance of Google Closure is terribly slow.

when I run my code.. it almost crash down Chrome browser.

Of course I did the same thing in HTML Canvas code not using Google Closure; It is super fast.

Here is my canvas code using Google Closure (goog.graphics.CanvasGraphics)

Since I am just a beginner in this module(goog.graphics.CanvasGraphics), I am not sure I did it correctly. Is there a something wrong I did?
Why is it so terribly slow??!!

It is too frustrating.

/** 
 * @param {Document} doct
 */
test.main = function(doct){
var dom = new goog.dom.DomHelper(doct);

/**
 * goog.graphics.CanvasGraphics(width, height, opt_coordWidth, opt_coordHeight, opt_domHelper)
 * @type {goog.graphics.CanvasGraphics} 
 */
var canvas = new goog.graphics.CanvasGraphics(500, 500, null, null, dom);
canvas.render(dom.getElement('canvasTest2'))
canvas.balls = [];






 function  drawScreen () {
    canvas.clear()

    for (var i =0; i <canvas.balls.length; i++) {
        ball = canvas.balls[i];
        ball.x += ball.xunits;
        ball.y += ball.yunits;
        var ellipse = canvas.drawEllipse(ball.x, ball.y, ball.radius, ball.radius, null, ball.solidFill);


        if (ball.x > canvas.width || ball.x < 0 ) {
            ball.angle = 180 - ball.angle;
            updateBall(ball);
        } else if (ball.y > canvas.height || ball.y < 0) {
            ball.angle = 360 - ball.angle;
            updateBall(ball); 
        }
    }

}

function updateBall(ball) {

    ball.radians = ball.angle * Math.PI/ 180;
    ball.xunits = Math.cos(ball.radians) * ball.speed;
    ball.yunits = Math.sin(ball.radians) * ball.speed;

}

var numBalls = 80;
var maxSize = 15;
var minSize = 5;
var maxSpeed = maxSize+5;

for (var i = 0; i < numBalls; i++) {

    var tempRadius = Math.floor(Math.random()*maxSize)+minSize;
    var tempX = tempRadius*2 + (Math.floor(Math.random()*canvas.width)-tempRadius*2);
    var tempY = tempRadius*2 + (Math.floor(Math.random()*canvas.height)-tempRadius*2);
    var tempSpeed = maxSpeed-tempRadius;
    var tempAngle =  Math.floor(Math.random()*360);
    var tempRadians = tempAngle * Math.PI/ 180;
    var tempXunits = Math.cos(tempRadians) * tempSpeed;
    var tempYunits = Math.sin(tempRadians) * tempSpeed;

    var stroke = new goog.graphics.Stroke(3, '#333');
    var solidFill = new goog.graphics.SolidFill('#333');

    tempBall = {x:tempX,y:tempY,radius:tempRadius, speed:tempSpeed, stroke:stroke, solidFill:solidFill, angle:tempAngle, xunits:tempXunits, yunits:tempYunits}

    canvas.balls.push(tempBall);

}

setInterval(drawScreen, 32);    


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T03:15:05+00:00Added an answer on June 7, 2026 at 3:15 am

    Maybe very obvious but did you tried it using Advanced Compilation? This removes dead code and optimizes your code. See https://developers.google.com/closure/compiler/docs/api-tutorial3 It might make the performance acceptable…

    Regards,

    Rene

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I test password recovery, but there are errors. Rspec study recently. code (User Controller)
I was recently tasked with performing a feasibility study based around switching from using
This might sound a bit un-realistic, but I've recently had to study the database
Recently I am trying to study how to run the apps in debug mode
Recently I've created a weather application for windows phone 7 using C#. But it
Recently I'm doing some work on RTMP streaming, that is using Flowplayer to integrate
Recently, we discovered odd behavior in some old code. This code has worked for
Recently,I am handling a solution for WebPart internationalization,but I am not familiar with the
Recently downloaded some code for a minor open-source project related to a small webgame
recently, while reading former's code in my current project, I encounter the problems below:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.