Skip to content

Instantly share code, notes, and snippets.

@pfrazee
Last active December 13, 2015 17:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pfrazee/4945450 to your computer and use it in GitHub Desktop.
Save pfrazee/4945450 to your computer and use it in GitHub Desktop.
Non-performant JS Patterns

It pains me to write this, because I prefer the more robust, function-composition-focused features of Javascript, but there's a threshold of performance where speed overrides elegance. After all, performance is half the reason that programming is skilled labor. So here we have it-- my list of performance benchmarks and advice.

The Unusable

Try / Catch -- Use conditionals instead

Try/Catch Performance may be pitting try/catch against an easy-to-optimize opponent, but it still makes a strong case.

Function Bind -- Use closure variables instead

Bind's Performance is pretty ugly. It hurts me to say that bind should only be used in the most extreme cases.

The First-To-Replace

.forEach/.map -- Replace with traditional loops

Loop vs map vs forEach shows ~7x difference; real, but not worrisome.

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