Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

optimizations from my state one #11

Merged
merged 1 commit into from May 20, 2013

Conversation

Projects
None yet
2 participants
Contributor

calvinmetcalf commented May 16, 2013

thanks to help from @natevw I was able to optimize the version I did of MA from 8 seconds to <2, these are the optimizations, which mainly involved removing map and forEach functions and replacing them with while loops, the two biggest speedups were

  1. Instead of calculating vector as a map of meta which we reduced, reduce directly on vector.
  2. Instead of calculating theta, from arctan2(dx,dy) and then latter doing sin(theta) and cos(theta), sin(arctan()) and cos(arctan()) can be simplified as
function sinArctan(dx,dy){
  var div = dx/dy;
  return (dy>0)?
    (div/Math.sqrt(1+(div*div))):
    (-div/Math.sqrt(1+(div*div)));
}
function cosArctan(dx,dy){
  var div = dx/dy;
  return (dy>0)?
    (1/Math.sqrt(1+(div*div))):
    (-1/Math.sqrt(1+(div*div)));
}
Calvin Metcalf optimizations b6238aa

@shawnbot shawnbot pushed a commit that referenced this pull request May 20, 2013

Shawn Allen Merge pull request #11 from calvinmetcalf/optimize
iteration and vector math optimizations
07c965f

@shawnbot shawnbot merged commit 07c965f into shawnbot:master May 20, 2013

Owner

shawnbot commented May 20, 2013

This is really, really awesome, Calvin. Thank you!

Contributor

calvinmetcalf commented May 20, 2013

no problem 😄

@calvinmetcalf calvinmetcalf deleted the calvinmetcalf:optimize branch May 20, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment