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

  • SEARCH
  • Home
  • 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 4259004
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:43:31+00:00 2026-05-21T05:43:31+00:00

When use the Google Closure Compiler advanced optimizations on the following code: function add(v1,

  • 0

When use the Google Closure Compiler advanced optimizations on the following code:

function add(v1, v2){
    return {x: v1.x + v2.x, y: v1.y + v2.y};
}

function lengthSq(vec){
    return vec.x*vec.x+vec.y*vec.y;
}

function test(v11, v12, v21, v22) {
    return lengthSq(add({x:v11, y:v12},{x:v21, y:v22}));
}
window['func']=test;

I get this unsatisfying result:

window.func = function(b, c, a, d) {
  b = {x:b, y:c};
  a = {x:a, y:d};
  a = {x:b.x + a.x, y:b.y + a.y};
  return a.x * a.x + a.y * a.y
};

What I was hoping for:

window.func = function(a, b, c, d) {
  return (a+c) * (a+c) + (b+d) * (b+d)
};

The real problem here is that I need to store values in attributes so that I can get multiple return values from functions. As far as I can tell, there is no other way to get multiple return values. I had initially hoped that the Closure Compiler would eliminate these for me, but it appears not.

Is it possible to have a functional or object oriented javascript library that can output code equivalent to the hand optimized example?

I am convinced my performance testing code is flawed, since the code without attributes is roughly 100 times faster on Chrome and Firefox, 12 times faster on Opera, and 4 times faster on IE9.

performance test of this code: http://jsperf.com/closure-compiler-vs-hand-optimized-vectors

  • 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-05-21T05:43:31+00:00Added an answer on May 21, 2026 at 5:43 am

    There is a pending change to the compiler under review that attempts to do this: http://code.google.com/p/closure-compiler/issues/detail?id=394

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

Sidebar

Related Questions

Any ideas on how to use Google Closure Compiler to combine multiple JavaScript files
Possible Duplicate: jQuery compiled with Google Closure Compiler I am using jQuery and I
I want to use Google spreadsheets to store data online so multiple people can
I want to use google chrome as a control. I think Enso does this
I would normally use Google analytics because it is free and simple to implement
I'm wanting to use google maps and see a million ways to do it
For all the RSS feeds I subscribe to I use Google Reader , which
Can I use the Google Finance API to get stock data? If there is
Since a lot of these sites found on google use mathematical notation and I
So Google Analytics does not have an API that we can use to get

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.