ES6 Feature Performance

by on Jun.25, 2015, under Dev

Update: The results below are a snapshot from when this post was written. kpdecker.github.io/six-speed/ has the most recent results.

With ES6 features landing quickly in native browsers and readily available for use through Babel and Traceur, it seemed like it was time to look not just at support, but also the performance impact of using these features under the current implementations.

While there is great promise for the future, the picture of ES6 feature performance today is very muddled and depends on the specific feature being used. Some such as bindings and simple arrow/destructuring are ready for use today, others such as generators and tagged template strings might require analysis before using.

The standard warnings of premature optimization and recommendations to profile your own code apply to the comments here. These tests are very micro in their scope and might not be representative of your particular use case. It’s also possible that the ES6 version is fast enough for your use case and is not worth additional time spent refactoring to a more complicated but faster implementation.

Results

Arrow Function

Arrow functions invocation has little performance impact under transpilers. Their native implementation under Firefox is 40-70x slower for calls than the equivalent ES5 operation. Internet Explorer’s performance is approximately that of ES5.

Arrow function declaration on the other hand is slightly slower than the most optimized ES5 implementation, under most environments. Here too Firefox’s implementation shows a large performance hit and IE shows a slight performance hit.

node chrome firefox internet explorer safari
0.10.39 2.3.0 43 44 45 38 39 40 11 12 8
arrow tests babel 1.3x slower Identical Identical Identical Identical Identical Identical Identical Identical 1.2x faster Identical
traceur 1.3x slower Identical Identical Identical Identical Identical Identical Identical Identical 1.3x faster Identical
es5-bind 10x slower 15x slower 19x slower 14x slower 20x slower 6x slower 6x slower 7x slower 4x slower 2.6x slower 3x slower
es6 38x slower 41x slower 52x slower Identical
arrow-args tests babel Identical Identical Identical Identical Identical Identical Identical Identical Identical 1.2x faster Identical
traceur Identical Identical Identical Identical Identical Identical Identical Identical Identical 1.2x faster Identical
es6 2.9x slower 64x slower 89x slower 68x slower 1.3x faster
arrow-declare tests babel 1.3x slower 1.3x slower Identical Identical Identical 8x slower 10x slower 13x slower 2.3x slower 1.6x slower 1.4x slower
traceur 1.3x slower 1.3x slower Identical Identical Identical 5x slower 7x slower 8x slower 2.3x slower 1.4x slower 1.4x slower
es6 Identical 53x slower 78x slower 78x slower 1.3x slower

Issues:

Classes

With classes we start to see some differences in behaviors. Traceur and the V8 native implementation operate at partity with the ES5 tests when looking at instantiation. Babel’s implementation does suffer a 1.5-60x performance hit for the operations tested. When compiling using Babel’s loose mode, the hit is lessened to 8x.

The super keyword has some fairly large performance issues under all implementations, with the best case being 3x slower and the worst case being 60x slower than the respective baselines. V8’s native implementation also sees a 15-20x performance hit.

Babel’s loose implementation of super is akin to that of the ES5 implementation, utilizing C.prototype.bar.call(this) rather than the slower getPrototypeOf lookup operation that while more accurate technically, incurs an additional cost. This is controlled by the es6.classes parameter but Babel’s authors cite a number of warnings with this flag that may impact compatibility when migrating code to native implementations.

node chrome firefox internet explorer safari
0.10.39 2.3.0 43 44 45 38 39 40 11 12 8
classes tests babel 2.3x slower 1.5x slower 1.3x slower 1.4x slower 1.3x slower 27x slower 26x slower 30x slower 1.4x slower 1.5x slower Identical
babel-loose 2.3x slower 1.5x slower 1.3x slower 1.4x slower 1.3x slower 6x slower 6x slower 8x slower 1.3x slower 2.4x slower Identical
traceur Identical Identical Identical Identical Identical 1.5x slower 1.7x slower 1.8x slower Identical Identical Identical
es6 Identical Identical Identical Identical
super tests babel 24x slower 60x slower 52x slower 48x slower 45x slower 60x slower 62x slower 61x slower 24x slower 24x slower 16x slower
babel-loose 2.0x slower 1.7x slower 1.7x slower 1.7x slower 1.7x slower 5x slower 5x slower 5x slower 3x slower 3.0x slower 1.2x slower
traceur 12x slower 26x slower 18x slower 18x slower 18x slower 26x slower 30x slower 27x slower 10x slower 12x slower 11x slower
es6 14x slower 19x slower 21x slower 18x slower

Issues:

Enhanced Object Literals

Object literal extensions generally provide an overhead of up to 147x the baseline. Under the transpiler implementations this is due to the use of defineProperty rather than the much more optimized field assignment. This is done to bullet proof code from potential edge cases discussed here. Loose mode is effectively the same as the ES5 implementation as of 5.6.7

node chrome firefox internet explorer safari
0.10.39 2.3.0 43 44 45 38 39 40 11 12 8
object-literal-ext tests babel 4x slower 60x slower 72x slower 71x slower 80x slower 1.8x slower 1.6x slower 1.6x slower 2.6x slower 2.0x slower 2.5x slower
babel-loose Identical 12x slower Identical Identical Identical Identical Identical Identical Identical Identical Identical
traceur 8x slower 120x slower 143x slower 122x slower 144x slower 3x slower 3x slower 2.9x slower 5x slower 4x slower 4x slower
es6 25x slower 23x slower 26x slower 1.4x slower 1.5x slower 1.3x slower Identical

Issues:

Template Strings

Template strings are a mixed bag. In the basic form, transpilers are able to hit parity with the baseline implementation under most environments. The native implementations are hit or miss. Under Chrome they execute at half the speed and under Firefox up to 650x slower.

Tagged template strings unfortunately do not have such a nice outlook. Their performance ranged from 2x slower for IE’s native implementation to 2000x slower for Babel’s implementation under Firefox. Babel’s loose implementation (es6.templateLiterals) lessens much of the overhead of this operation, at the cost of not having a fully compliant String.raw implementation.

Issues:

node chrome firefox internet explorer safari
0.10.39 2.3.0 43 44 45 38 39 40 11 12 8
template_string tests babel Identical Identical Identical Identical Identical Identical Identical Identical 1.5x faster 1.4x faster Identical
traceur Identical Identical Identical Identical Identical Identical Identical Identical Identical Identical Identical
es6 Identical 2.0x slower 2.0x slower 1.9x slower 627x slower 622x slower 591x slower 1.3x faster
template_string_tag tests babel 567x slower 578x slower 722x slower 755x slower 820x slower 2395x slower 2349x slower 2028x slower 90x slower 82x slower 61x slower
babel-loose 2.0x slower 1.6x slower 1.7x slower 1.6x slower 1.8x slower 94x slower 87x slower 84x slower 1.4x slower 1.4x slower 2.0x slower
traceur 7x slower 13x slower 17x slower 13x slower 16x slower 346x slower 307x slower 261x slower 13x slower 11x slower 8x slower
es6 8x slower 9x slower 13x slower 9x slower 68x slower 64x slower 59x slower Identical

Destructuring

For destructuring, the average use case effectively matches that of the ES5 counterpart. Unfortunately complex use cases, particularly those around array destructuring, often have large performance overhead. Under Babel an unoptimized helper is used to access the data and under Traceur an entire iterator structure is created, both of which provide fairly substantial memory and CPU overhead over the simple array accessor logic that hand coded ES5 can utilize. Loose mode is effectively the same as the ES5 implementation.

node chrome firefox internet explorer safari
0.10.39 2.3.0 43 44 45 38 39 40 11 12 8
destructuring tests babel 1.8x slower 1.4x slower 1.4x slower 1.2x slower 1.3x slower 24x slower 22x slower 26x slower 3x slower 5x slower 2.2x slower
babel-loose 1.2x faster Identical Identical 1.2x faster Identical Identical Identical Identical Identical Identical Identical
traceur 26x slower 13x slower 12x slower 10x slower 11x slower 163x slower 152x slower 176x slower 57x slower 25x slower 8x slower
es6 170x slower 148x slower 185x slower Identical
destructuring-simple tests babel Identical Identical Identical Identical Identical Identical Identical Identical 10x slower 1.2x slower Identical
traceur Identical Identical Identical Identical Identical Identical Identical Identical Identical 1.3x slower Identical
es6 Identical Identical Identical Identical

Issues:

Default Parameters

Default parameters were universally slower for all transpiler implementations. They effectively compile to the same thing, utilizing the arguments object to set a local variable vs. using a named paramemter. This appears to be unoptimzed under all engines and consequently performance was 4-2000x slower. Sadly, this is required in order to properly implement the fn.length behavior defined by the spec:

NOTE The ExpectedArgumentCount of a FormalParameterList is the number of FormalParameters to the left of either the rest parameter or the first FormalParameter with an Initializer. A FormalParameter without an initializer is allowed after the first parameter with an initializer but such parameters are considered to be optional with undefined as their default value.

These scaled numbers should be taken in context. The ES5 equivalents are highly optimized, Firefox pushing over 833 million operations a second in one test, so the net performance of the transpiled versions may very well be sufficient for most use cases, particularly those not on the hot path.

The only native implementation, Firefox, performed identically to the ES5 implementation.

node chrome firefox internet explorer safari
0.10.39 2.3.0 43 44 45 38 39 40 11 12 8
classes tests babel 2.3x slower 1.5x slower 1.3x slower 1.4x slower 1.3x slower 27x slower 26x slower 30x slower 1.4x slower 1.5x slower Identical
babel-loose 2.3x slower 1.5x slower 1.3x slower 1.4x slower 1.3x slower 6x slower 6x slower 8x slower 1.3x slower 2.4x slower Identical
traceur Identical Identical Identical Identical Identical 1.5x slower 1.7x slower 1.8x slower Identical Identical Identical
es6 Identical Identical Identical Identical
defaults tests babel 17x slower 11x slower 11x slower 9x slower 8x slower 1842x slower 2051x slower 2043x slower 229x slower 72x slower 4x slower
traceur 16x slower 12x slower 12x slower 10x slower 9x slower 1759x slower 2305x slower 1974x slower 210x slower 73x slower 4x slower
es6 Identical Identical Identical

Rest Parameters

Rest parameters are as fast or faster than the ES5 equivalent under almost all implementations. Native implementations provided a performance boost up to 40x (with the exception of V8 where it causes a known deoptimization). Use them with a transpiler. They’re great. Death to arguments.

node chrome firefox internet explorer safari
0.10.39 2.3.0 43 44 45 38 39 40 11 12 8
rest tests babel Identical Identical Identical Identical Identical Identical Identical Identical 2.0x slower 1.5x slower Identical
traceur Identical 1.5x faster 1.2x faster 1.2x faster 1.2x faster 31x faster 34x faster 27x faster 2.4x slower 1.6x slower 1.3x faster
es6 3x slower 40x faster 42x faster 32x faster 8x faster

Spread Parameters

Under Babel, spread parameters for arrays perform identically to the ES5 counterpart as they are effectively both an apply call. Under Traceur and all of the native implementations the implementations are 1.3x to 17x slower.

node chrome firefox internet explorer safari
0.10.39 2.3.0 43 44 45 38 39 40 11 12 8
spread tests babel Identical Identical Identical Identical Identical Identical Identical Identical Identical Identical Identical
traceur 13x slower 6x slower 5x slower 6x slower 6x slower 2.7x slower 3x slower 3x slower 9x slower 712x slower 17x slower
es6 3x slower 4x slower 4x slower 1.3x slower 2.5x slower
spread-generator tests babel 150x slower 55x slower 58x slower 66x slower 71x slower 153x slower 143x slower 157x slower 656x slower 423x slower 64x slower
babel-loose 114x slower 46x slower 41x slower 45x slower 53x slower 60x slower 60x slower 61x slower 28x slower 51x slower 22x slower
traceur 27x slower 10x slower 9x slower 10x slower 13x slower 11x slower 10x slower 11x slower 15x slower 1551x slower 9x slower
es6 7x slower 8x slower 7x slower
spread-literal tests babel Identical Identical Identical Identical Identical 1.2x slower Identical 1.2x slower 3x slower 1.7x slower 2.0x slower
traceur 6x slower 3.0x slower 2.1x slower 2.5x slower 2.3x slower 6x slower 5x slower 5x slower 26x slower 451x slower 9x slower
es6 8x slower 7x slower 8x slower 1.8x slower 3x slower

Let + Const

let and const bindings were pretty much identical across the board. While these don’t offer performance improvements (yet), they shouldn’t negatively impact performance.

node chrome firefox internet explorer safari
0.10.39 2.3.0 43 44 45 38 39 40 11 12 8
bindings tests babel Identical Identical Identical Identical Identical Identical Identical Identical Identical Identical Identical
traceur Identical Identical Identical Identical Identical Identical Identical Identical Identical 1.3x faster Identical
es6 Identical Identical Identical Identical Identical 2.3x slower Identical Identical 1.3x slower Identical

For..of

for..of is universally slower, ranging from 3 to 20x slower for array iteration over classical array iteration. When iterating over an object with a custom iterator, the performance is also much slower than for..in iteration with hasOwnProperty checks.

node chrome firefox internet explorer safari
0.10.39 2.3.0 43 44 45 38 39 40 11 12 8
for-of-array tests babel 21x slower 8x slower 8x slower 9x slower 9x slower 14x slower 20x slower 19x slower 15x slower 489x slower 7x slower
babel-loose Identical Identical Identical Identical Identical 1.4x slower 1.7x slower 1.7x slower 1.3x slower Identical 1.8x slower
traceur 12x slower 7x slower 7x slower 8x slower 8x slower 26x slower 31x slower 32x slower 9x slower 6x slower 6x slower
es6 6x slower 6x slower 8x slower 8x slower 5x slower 7x slower 7x slower 2.9x slower 4x slower
for-of-object tests babel 10x slower 7x slower 8x slower 9x slower 6x slower 6x slower 6x slower 5x slower 60x slower 11x slower 6x slower
babel-loose 10x slower 6x slower 7x slower 9x slower 7x slower 4x slower 4x slower 4x slower 6x slower 449x slower 6x slower
traceur 8x slower 7x slower 8x slower 9x slower 7x slower 9x slower 10x slower 9x slower 5x slower 4x slower 4x slower
es6 6x slower 7x slower 8x slower 6x slower 3x slower 3x slower 3x slower 3x slower

Generators

Much like for..of, generators are also quite a bit slower than a raw ES5 implementation of the iterable protocol, with performance ranging from 10x to 750x slower. There is hope here as the V8 implementation achieves parity with the ES5 implementation.

node chrome firefox internet explorer safari
0.10.39 2.3.0 43 44 45 38 39 40 11 12 8
generator tests babel 601x slower 65x slower 67x slower 63x slower 69x slower 754x slower 723x slower 716x slower 79x slower 499x slower 78x slower
traceur 77x slower 10x slower 10x slower 10x slower 12x slower 48x slower 50x slower 46x slower 18x slower 112x slower 10x slower
es6 Identical 1.2x slower Identical Identical 22x slower 20x slower 19x slower

Issues:

Maps and Sets

Map and Set all have insert performance that is about 10x slower for a moderately sized data set. All of the implementations show massive improvement on the lookup operations, with Firefox’s native implementation showing a 200x speed increase for a dataset of size 500.

Traceur appears to delegate to the native implementation via their polyfill where possible so performance is closely linked to improvements in the native layer. In runtime mode, Babel does not appear to delegate and performance suffers as a result. Babel’s polyfill mode should behave as Traceur does but this was not directly tested.

Take caution with these numbers. The tests use a data set of size 500 and other data sets will have varying performance but it appears that these features are ready for general use if you have many reads and few writes or need to have objects as keys.

node chrome firefox internet explorer safari
0.10.39 2.3.0 43 44 45 38 39 40 11 12 8
map-set tests babel 13x slower 3.0x slower 5x slower 5x slower 3.0x slower 105x slower 12x slower 15x slower 60x slower 19x slower 79x slower
traceur 5x slower Identical 2.2x slower 2.3x slower 1.6x slower 20x slower 2.5x slower 2.4x slower 28x slower 2.2x slower 16x slower
es6 5x slower Identical 2.2x slower 2.3x slower 1.6x slower 21x slower 2.2x slower 2.7x slower 28x slower 2.2x slower 15x slower

Promises

Promises are across the board faster with both the polyfill and native implementations. This particular benchmark is dubious as it’s both async and inheriently tied to long running behaviors where execution overhead has little impact.

node chrome firefox internet explorer safari
0.10.39 2.3.0 43 44 45 38 39 40 11 12 8
promises tests babel Identical Identical 6x faster 7x faster 7x faster 21x faster 17x faster 16x faster Identical 1.2x slower 3x faster
traceur Identical Identical 2.0x faster 2.0x faster 1.9x faster 36x faster 31x faster Identical Identical 1.8x slower 3x faster
es6 Identical 2.0x faster 2.0x faster 1.9x faster 37x faster 29x faster Identical 1.9x slower 3x faster

Testing methodology

For each of the ES6 features in question, a ES5 implementation of that functionality was written along with a ES6 version. It should be noted that the functionality is frequently the same, but in some cases the “common” vs. “correct” version was written, i.e. using x[key] = value vs. defineProperty which is faster but can be hit but a particular nasty edge case for those who deem it fun to extend Object.prototype.

Babel, in both loose+runtime and runtime mode, and Traceur were then used to compile the ES6 version to a ES5 compliant version, utilizing the runtime over polyfill to maintain test isolation and avoid native implementations where possible.

All of these test instances were then benchmarked in the given JavaScript engine using Benchmark.js and then the operations per second compared to the ES5 implementation. Cross browser and cross execution comparisions are avoided as much as possible to isolate environmental issues when executing on VMs in the cloud.

All of this data, including any updates from more recent test runs is available at http://kpdecker.github.io/six-speed/ and the test suite is available at https://github.com/kpdecker/six-speed for review/feedback.

Takeaways

As noted above, these results might not be representative of your own application since they only test very small subsets of inputs and behaviors of these new features. If you are finding that you have performance issues with your code using these features, you should test them within your own environment to see what the actual behavior is.

While some of these features are a bit slow as of this writing, their performance should only improve as the native implementations mature and are optimized as real world use is applied to them. For the transpilers, there are some performance optimzations that can be made but much of the overhead they are experiencing is due to spec compliance, which they go to great lengths to achieve, but this comes with unfortunate overhead under ES5 implementations as they stand. Babel’s loose mode does offer a bit of a performance boost, but care must be taken when using loose mode as this could cause breakages when code is migrated to the standard native implementations.

Personally I intend to start using most of these features where they make sense but will avoid designing core APIs around these features (perhaps with the exception of Promises) until the native implementations have matured a bit.

4 Comments :, , more...

May Conference Recap

by on Jun.03, 2013, under Web Dev

I had the pleasure of attending portions of Google IO, CSS Conf, and JS Conf and wanted to summarize my notes on these conferences. These are my own take aways and may not have been what the presenter intended. If I’m completely off base, please feel free to drop me a line. This is also not inclusive as there are only so many sessions that one can attend :)

Major Trends

Componentization

Biggest theme of all of these conferences was attempting to create ways of compoentizing our code so that we can leave the smell of the poo all in one place, to paraphrase @danwrong.

Polymer

Google has the Polymer framework which polyfils web components. The premise is that you can create truly isolated components that are drop in and do not have worries such as CSS impact from other components.

<element name="my-element">
  <section>
    I'm a my-element!
  </section>
  <footer>nothing to see here</footer>
  <script>
    // When <element> is in document, might run in wrong context.
    // Only do work when this == <element>.
    if (this !== window) {
      var section = this.querySelector('section');
      this.register({
        prototype: {
          readyCallback: function() {
            this.innerHTML = section.innerHTML;
          }
        }
     });
    }
  </script>
</element>

This looks pretty amazing and I think will provide some awesome separation of concerns between content and behaviors in the future. Polyfilling this behavior seems outright genius but at the same time scares me as you are basing a lot of your implementation on something that is being hacked into the browser.

I’m of the opinion that this is amazing future looking work but is a bit more risk than I’d like to take on for my user base.

With standards support for this moving forward I think this is where we will be in 5-10 years depending on the user base that a project is required to support. I also believe that there is a huge opportunity here for developer tooling as this changes some things up that will require changes and improvements to our existing hint/test/minimize/etc tool stacks.

React

Facebook is doing similar work with their React framework. They have created a new compiled to JavaScript language that allows one to embed html into the source file:

var HelloMessage = React.createClass({
  render: function() {
    return <div>{'Hello ' + this.props.name}</div>;
  }
});

The framework will then manage the all of the rendering lifecycle without data binding or blanket re-rendering. This is apparently done by a DOM diffing algorithm that walks the DOM tree and updates only the components that need to be on a property change. The presenting team highlighted that you can provide hints to this implementation to improve performance so I do question how well this scales.

I have not had a chance to play around with this implementation but I am not against the html embedded in a JavaScript file like many people in the blogosphere are/have been. I think both this and polymer tackle separation of concerns in a different manner than the HTML/CSS/JS paradigm that has been beat into web developers for so long. I see them as implementing separation of concerns at a content vs. behavior level which may be better for some workflows.

Flight

Flight from Twitter attempts to handle componetization at a much smaller level. They focus on defining interfaces between discrete components. Each of these components can focus on only their implementation.

This is lower-level than the systems above and in many ways can be used to build other framework systems.

Performance

Performance was a huge concern at all 3 conferences with many sessions devoted to different aspects of performance improvements. My major take aways are:

  • Don’t follow a coding pattern because something is “faster”. What exactly is faster will change as runtimes optimize for the code that they are seeing. Instead look at what the tools are saying and react accordingly.

  • Don’t prematurely optimize. You are probably wrong. Your code is most likely going to be harder to understand and there is plenty that you can spend time as engineering time is finite.

  • Performance is holistic.

    • JavasScript, layout, rendering, compositing, GC, etc. can all impact performance.
    • Newer architectures are moving behaviors out to other threads but this does not work if you try to implement your own behavior. Custom scrolling is the biggest offender here.
    • Under current Chrome implementations touch handlers can cause scrolling issues as it disables certain scrolling optimizations.
  • Chrome is the leader in debugging tools and ability to investigate performance

    • Chrome dev tools timeline panel
    • about:tracing – Google’s internal performance tool
    • V8 tools – In depth V8 profiling tools
    • Continuous painting mode lets you test performance impact of specific elements or properties
    • Remote debugging API (This powers Chrome for Android debugging and topcoat performance monitor)
  • Higher level console commands are useful

    • console.time
    • console.group
    • These are not always evil and can help programmers with onboarding
  • Topcoat has a turbo mode which attempts to remove layout and style calculation from overhead. All elements have style element and are absolutely positioned. On a personal note this seems a bit overboard for 99% of use cases.

  • High-speed cameras can be used in the name of performance testing! :)

Many V8 specific performance recommendations as well:

  • V8 has an optimized/unoptimized state machine that a particular piece of code may jump between. Can’t tell at compile time if something will be promoted to optimized once hot. When profiling should look for * token next to function names to verify that it’s optimized.

  • Memory allocation pattern between optimized and unoptimized are dramatically different. Optimized will often remove temp variables wereas unoptimized will have to GC temp variables.

  • Can monitor state machine with --js-flags="--trace-deopt --trace-opt-verbose". WARN: Very verbose. Pipe & Grep

Better Tooling

Adobe and Google had strong developer tools showings at these conferences.

Adobe demoed some very cool features for their brackets IDE including:

  • PSDLens – PSD inspector assistant
  • Response – Responsive design editor
  • Theseus – Brackets debugger concept
  • Instabug – Live code inspector with visual unit test executor/generator

Additionally they covered some of the tools involved with their topcoat project:

On the Google front, most of the improvements were in the Chrome Developer Tools including:

  • Flame charts
  • Full remote dev tools on Chrome For Android
  • SASS support, generically via source maps
  • Live editing with mapped update support

JavasScript everywhere

One of the other fun themes was the use of JavaScript in more and more places. This included a hacking day on various bots and AR Drones for those who choose those sessions. This culminated with a Nodebot shooting down a NodeCopter and calls for Node-based Aircraft Carriers.

Random Coolness

  • jankfree.org
  • nodesecurity.io
  • webplatform.org
  • @rem demoing game with RTC and getUserMedia
  • @seb_ly giving an amazing presentation including crowd participation from 5000 miles away and live coding over VNC
  • @necolas – Get over yourself. Tech changes every few years and all of the battles today will likely be moot in a few years.

Outside of the above there we’re a lot of fun and interesting sessions that could be discussed in depth but suffice to say that the JavasScript and Web Development communities are very strong and there is a lot of interesting stuff coming down the pipes.

Comments Off on May Conference Recap :, more...

OSX Frontend Toolchain

by on Jan.30, 2013, under Dev

I’m currently in the middle of inventorying my machine so I can retire the time machine image that has spanned far too many years and far too many machines. Rather than stuffing this in Evernote to be used once I figured I’d post this to the community.

What other frontend tools are missing? Which ones have better alternatives?


Editors

  • SublimeText 2

    Common plugins include:

    • Package Control – Allows all other plugins to be installed
    • BracketHighlighter
    • Git
    • Handlebars.tmBundle
    • JsFormat
    • JsHint
    • PrettyJSON
    • Stylus
    • SublimeSaveOnBuild
    • TrailingSpaces

    Useful config options:

    {
      "bold_folder_labels": true,
      "draw_white_space": "all",
      "ensure_newline_at_eof_on_save": true,
      "file_exclude_patterns":
      [
        "*.tmproj",
        "*.sublime-workspace",
        "*.class",
        ".DS_Store"
      ],
      "folder_exclude_patterns":
      [
        ".svn",
        ".git",
        ".hg",
        "CVS",
        "node_modules"
      ],
      "highlight_line": true,
      "highlight_modified_tabs": true,
      "rulers":
      [
        100
      ],
      "tab_size": 2,
      "translate_tabs_to_spaces": true
    }
    

SCM

  • Git Command Line

    Your mileage may vary but by far the strongest git client out there.

    Most common git commands

    • git checkout -b $newBranchName
    • git stash
    • git pull --rebase (Warn do not do after a branch merge)

    Ensure that your version of git has completions enabled (this might require manual installation)

    Customizing your bash prompt for git status is also very helpful:

    This script whose origin has been lost will output the current branch and change status in your bash profile.

    function parse_git_branch {
      git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
    }
    function last_two_dirs {
      pwd |rev| awk -F / '{print $1,$2}' | rev | sed s_\ _/_
    }
    
    c_cyan=`tput setaf 6`
    c_red=`tput setaf 1`
    c_green=`tput setaf 2`
    c_sgr0=`tput sgr0`
    
    function proml {
      PS1='\h:$(last_two_dirs)\[$(branch_color)\]$(parse_git_branch)\[${c_sgr0}\] \u\$ '
    }
    function branch_color() {
      if git rev-parse --git-dir >/dev/null 2>&1
      then
        color=""
        git diff --quiet 2>/dev/null >&2
        if [[ $? -eq 0 ]]
        then
          color=${c_cyan}
        else
          color=${c_red}
        fi
      else
        return 0
      fi
      echo -ne $color
    }
    
    proml
        
  • Gitx

    GUI frontend on various commit related git operations. The staging view is very valuable for doing interactive commits and self-code review at commit time.

  • SourceTree

    General git repository viewer. Helpful for viewing stashed changes that may have accumulated on your local tree.

  • git-extras

    A collection of useful tools for doing higher level git commands such as delete-branch. When installing make sure that the command line tab completion tools to no error out as these are very helpful.

Debugging and Optimizing

  • Charles

    HTTP proxy and debugger with easy to use interface.

  • xScope

    Inspect/measure mocks and final rendered pages.

  • Gradient Scanner

    (Shameless plug) Extract CSS gradients from flatted mock images.

  • ImageAlpha/ImageOptim

    Image optimization tools. Performs both lossless and lossy compression of image assets.

Documents

  • Dropbox

    Easy way to backup remotely and share content across the team.

  • Evernote

    Free notetaking service.

  • MS Office

    Because somethings you can’t escape.

  • MS Remote Desktop Client

    Again somethings you can not escape.

Communication

  • Adium

    Chat over many protocols. Most common among the team are GTalk and AIM.

  • Propane

    Team chat. Setup growl notifications and stay connected.

  • Skype

    Sometimes you need to use your voice. Horrible at IM.

  • ScreenFlow

    Generate screen casts for sharing content with coworkers or debugging transient behaviors.

System

  • Alfred

    Search-based system launcher.

  • Growl

    Common notification system for Lumbar builds and Propane and others.

  • Divvy

    Window position manager

  • Stay

    Utility which will restore your windows when you connect or disconnect a monitor.

  • BetterTouchTool

    Keyboard/mouse/touchpad gesture mapper.

  • Cloud App

    Dirt simple screenshot sharing app. Useful for sharing screenshots and other local content over IM and email when attachments might not be supported or supported easily.

  • Homebrew

    OSS package manager.

  • nvm

    Node version switcher. Easily allows for switching between different versions of node.

    Current recommendations for the latest 0.8 node branch for running the development build stack as the watch issues on the 0.8 branch seem to have been resolved.

3 Comments :, , , more...

Lumbar: Modular Javascript Build

by on Jan.17, 2012, under Web Dev

Since joining @WalmartLab’s mobile web team close to a year ago we have been very busy rebuilding the mobile web platform using Backbone, Handlebars, Stylus and other awesome open source tools and frameworks.

Even though these tools allow for some pretty impressive feats of javascript, we kept hitting inefficiencies both in execution and developer time due to resource loading and management.

When dealing with handlebars for example, we consistently found that we were trying to fight against the system to manage the templates used by a view. We neither wanted to manually inline the template in the javascript as we all know that escaping a language within a language is just painful, ala Java running SQL, nor did we want to add the additional overhead of an additional request for deferred loading of templates or worse inlining all application templates within the html file.

Being both constrained by the mobile environment and needing to operate at the scale of Walmart it became apparent very quickly that we needed to have some sort of build-time utility to manage this so the developer can focus on creating the application logic, throw it into the build tool and out comes a nicely optimized module of code and styles.

Lumbar along with the associated Lumbar projects such as lumbar-loader and lumbar-long-expires are the fruits of these efforts.

Overview

The Lumbar suite focuses on the management of all resources required to generate complex javascript applications across many different platforms and environments. It’s primary goals are to easily package, optimize, link to resources such as javascript, html, templates, styles, images, and any other client-side resources that web application may require.

From it’s initial implementation, Lumbar has focused on making client performance the number one goal, to this end it allows for chunking resources into distinct code modules, easy minification, inlining, and cache management.

Configuration

Lumbar is configured through a simple JSON config file, defining modules which are simple, demand loaded, segments of the application.

A base module that loads the core application:
    "base": {
      "scripts": [
        {"src": "js/lib/zepto.js", "global": true},
        {"src": "js/lib/underscore.js", "global": true},
        {"src": "js/lib/backbone.js", "global": true},
        {"src": "js/lib/handlebars.js", "global": true},
        {"src": "js/lib/thorax.js", "global": true},
        {"src": "js/lib/script.js", "global": true},
        {"src": "js/lib/lumbar-loader.js", "platform": "web"},
        {"src": "js/lib/lumbar-loader-standard.js", "platform": "web"},
        {"src": "js/lib/lumbar-loader-backbone.js", "platform": "web"},
        "js/init.js",
        {"src": "js/bridge.js", "platforms": ["iphone", "ipad", "android"]},
        {"src": "js/bridge-android.js", "platform": "android"},
        {"src": "js/bridge-ios.js", "platforms": ["ipad","iphone"]},
        {"module-map": true}
      ],
      "styles": [
        "styles/base.styl",
        {"src": "styles/iphone.styl", "platform": "iphone"},
        {"src": "styles/android.styl", "platform": "android"},
        {"src": "styles/ipad.styl", "platform": "ipad"},
        {"src": "styles/web.styl", "platform": "web"}
      ],
      "static": [
        {"src": "static/#{platform}/index.html", "dest": "index.html"}
      ]
    },

A router-linked module. When using backbone/thorax integration, this module will automatically load when the # or #hello routes are navigated:
    "hello-world": {
      "routes": {
        "": "index",
        "hello": "index"
      },
      "scripts": [
        "js/views/hello-world",
        "js/routers/hello-world.js"
      ],
      "styles": [
        "styles/hello-world.styl"
      ]
    }

This config file also defines the platforms that lumbar will generate, allowing for customizing the modules for different environments ("platforms": [ "android", "iphone", "ipad", "web" ]). At @WalmartLabs we utilize this to serve customized experiences for the native clients utilizing the same codebase.

Walmart Checkout Designs

Single stylus codebase styled for iPhone, Android, and mobile web platforms.

Walmart Checkout - iPad

More dramatic customizations of the same codebase utilizing platform conditional code.

The final component of the configuration is the packages component, which allows for bundling specific modules into singular responses when a particular use case only uses a subset of modules, such as the native checkout implementations utilized by @WalmartLabs.

  "packages": {
    "web": {
      "platforms": [ "web" ],
      "combine": false
    },
    "native-hello-world": {
      "platforms": [ "android", "iphone", "ipad" ],
      "modules": [ "base", "hello-world" ],
      "combine": true
    }
  },
Package declarations defining normal loading for web and combined for native platforms.

On building this will generate the following structure:

    $ find . -type f
    ./android/index.html
    ./android/native-hello-world.css
    ./android/native-hello-world.js
    ./android/native-hello-world@1.5x.css
    ./ipad/index.html
    ./ipad/native-hello-world.css
    ./ipad/native-hello-world.js
    ./iphone/index.html
    ./iphone/native-hello-world.css
    ./iphone/native-hello-world.js
    ./iphone/native-hello-world@2x.css
    ./web/base.css
    ./web/base.js
    ./web/base@2x.css
    ./web/hello-world.css
    ./web/hello-world.js
    ./web/hello-world@2x.css
    ./web/index.html

Which can be deployed as static resources to any web server, served via a CDN, or distributed by many other means.

While not a core feature, the lumbar-long-expires plugin takes this a step further by allowing resources to include expires tokens in their names automatically. When enabled the above may generate content like the following, allowing for the application resources to be served with extended Expires headers.

    $ find . -type f
    ./android/cb188f8/native-hello-world.css
    ./android/cb188f8/native-hello-world.js
    ./android/cb188f8/native-hello-world@1.5x.css
    ./android/index.html
    ./ipad/cb188f8/native-hello-world.css
    ./ipad/cb188f8/native-hello-world.js
    ./ipad/index.html
    ./iphone/cb188f8/native-hello-world.css
    ./iphone/cb188f8/native-hello-world.js
    ./iphone/cb188f8/native-hello-world@2x.css
    ./iphone/index.html
    ./web/cb188f8/base.css
    ./web/cb188f8/base.js
    ./web/cb188f8/base@2x.css
    ./web/cb188f8/hello-world.css
    ./web/cb188f8/hello-world.js
    ./web/cb188f8/hello-world@2x.css
    ./web/index.html

The @WalmartLabs mobile team believes strongly in open source software which is why in addition to open sourcing Lumbar we are also open sourcing our Thorax framework. If you are a backbone user looking to ease common tasks such as data binding and linking data operations to a particular route I urge you to take a look. It even integrates with Lumbar!

Comments Off on Lumbar: Modular Javascript Build :, , , , more...

Quick: Firediff and Firefocus updated for 5.0 support

by on Jul.06, 2011, under Firediff, Firefocus

Both Firediff and Firefocus have been updated to increase the target application support up to Firefox 5.0.

Both of these are available from the update stream on this site. New installations are recommended to use the Firediff and Firefocus projects on AMO as these will be more responsive to the march of Firefox releases.

Comments Off on Quick: Firediff and Firefocus updated for 5.0 support :, , , , more...

Firediff 1.1.2

by on Mar.21, 2011, under Firediff, Firefox, Web Dev

Just in time for the impending Firefox 4.0 release, Firediff has been updated to version 1.1.2. This release contains compatibility changes for Firefox 4.0 and Firebug 1.7 as well as the ability to sort CSS properties alphabetically.

As always, the latest version is available here and is currently under review at AMO.

2 Comments :, , more...

Firediff 1.1.1

by on Dec.22, 2010, under Dev, Firediff, Firefox, Web Dev

Firediff has been updated to 1.1.1 on the incaseofstairs servers. This version is a minor bug release that fixes the Save Diff and Snapshot functionality.

Updated package is available here and is under review at AMO

Thanks to Borris and Joel for letting me know about this issue. Feel free to contact me with any other issues you may have found.

Comments Off on Firediff 1.1.1 more...

Firebug Extension Updates: Firebug 1.6

by on Dec.03, 2010, under Firediff, Firefocus

As many of you are already aware, the recent release of Firebug 1.6 introduced some API changes that caused breakages within Firediff. To fix these some minor code changes within Firediff were necessary, thus the 1.1 release that has just been published.

Along with the updates for the new APIs, this version also includes:

  • Copy support
  • Bug fixes for Firebug detached mode
  • Change monitor context menu fixes
  • Slight adjustment to the colors used within the text diffs

There are a few support changes in this release. Rather than trying to support multiple versions of both Firebug and Gecko, official testing is limited to a single version of Firebug, 1.6, and as a consequence for Firebug 1.6 to a single version of Firefox, 3.6. This is simply due to the increased QA time that is required to test all of the permutations of Firebug version, Gecko version, and OS type. When updating for the changed APIs in Firebug 1.6 attempts were made to maintain compatibility with Firebug 1.5, but this configuration is no longer officially tested.

Since I was going to through the release process for Firediff I decided to release the 1.2 version of Firefocus as well. This version implements the uk-UA locale but is otherwise the same as 1.1.

Firediff 1.1 is available here on incaseofstairs and is currently under review on AMO. Firefocus 1.2 is available here on incaseofstairs and is currently under review on AMO.

Thanks to everyone who notified me of the breakage when 1.6 was released. It’s great to hear feedback from users and to hear that the project is in active use! As always please do not hesitate to let me know how the project is working for you, good or bad.

6 Comments :, , , more...

Cross Platform Text-Indexer

by on Nov.25, 2010, under Web Dev, webOS

While working on a recent Facebook release we ran into a performance bottleneck within the Mojo.Format.runTextIndexer API. Performance on device was on the order of a couple of seconds to process the content for feed items 30-50. This combined with the other tasks in the formatting and rendering cycle led to poor performance in the news stream.

For those who are not familiar with the Mojo.Format.runTextIndexer API, this API scans human generated text for URLs, phone numbers and email addresses, replacing the plain text representation with HTML links to the particular object. Additionally this API will replace emoticons with image representations on supporting platforms.

With the news stream scene being the primary scene in the application it was vital that we make this as performant as possible so I spent some time profiling this and determined that the bulk of the time in this operation was spent in the generic C indexer logic. Since at it’s core this is just a text scanning heuristic that, for the most part, does not rely on any C-level constructs, I decided to investigate a Javascript implementation to see if this would be more performant.

The result was a Javascript implementation that was many magnitudes faster than the core implementation (multiple seconds vs. ~10ms for a variety of Facebook news feeds), allowing for much faster execution as well as the creation of the library being released today.

While this library is designed primarily for webOS applications, it has also been designed to work in cross-platform environments for all functionality other than the emoticon replacement which requires platform specific logic to determine the proper image to replace.

Implementation

There are two key components to this implementation, the cross platform link indexer and the platform specific emoticon processor.

The link indexer is a two-stage regular expression, using the quite daunting INDEXER_REGEX regex to extract possible linker tokens with Javascript being used to determine the meaning of each token (or throwing it out just text content).

The emoticon processor is implemented by scanning for known, or possibly known, emoticons using the EMOTICON_REGEX regex and then passing these tokens to the platform’s text indexer implementation. Doing this allows for our own custom implementation while retaining the look and feel of emoticons used by the rest of the platform. For non-Mojo platforms this logic is disabled and emoticons will be left unmodified, with minimal change.

Warnings

HTML Content

Like the API this aims to replace, this API does not handle HTML context when replacing content. As a consequence this algorithm can break HTML content. In order to prevent this, the input and outputs for the TextIndxer.run API should be considered text or minimal HTML that will not match any of the replacements.

It is still possible to use this with content containing HTML by processing in a manner similar to the following although the input still needs to be filtered for XSS and other security concerns.

        var srcText = $(this).val(),
            womb = $("<div>" + srcText + "</div>");

        womb.contents()
            .filter(function() {
                return this.nodeType === Node.TEXT_NODE;
            })
            .each(function() {
                var text = $(this),
                    indexedText = TextIndexer.run(text.text()),
                    womb = $("<div>" + indexedText + "</div>");
                womb.contents().each(function() {
                    text.before(this);
                });

                text.remove();
            });

        $("#previewContent").html(womb.html());

Framework Override

By default this library overrides the Mojo.Format.runTextIndexer API (when used within the Mojo framework). Care should be taken with each OS upgrade to ensure that this override does not break any expected behavior. If uncomfortable with this override then it can be removed by removing these lines from the library and using the TextIndexer.run API directly.

    // Mojo Framework override. Unused on non-Mojo platforms and may be removed if undesired in Mojo apps
    if (window.Mojo && Mojo.Format) {
        // Override the Mojo API if it exists in this context.
        Mojo.Format.runTextIndexer = TextIndexer.run;
    }

Code

The code is available on Github within the text-indexer repository. A cross-platform live demo is also available here.

3 Comments :, , , more...

jsPerf

by on Aug.01, 2010, under Web Dev

Recently heard about the relatively new jsPerf service that Mathias Bynens has created and after spending some time playing around with this on my own machine I can honestly say that I love this service. Rather than a few gushing tweets on the subject, I felt like this deserves a blog entry covering it’s coolness.

The thing that I found the most striking about the site (and most likely the reason that I am writing this now) is that it broke many of my previous assumptions about performance of specific statements and relative performance of different platforms. Is innerHTML faster than DOM manipulation when generating a DOM tree? Not for a specific (relatively simple) construct under Chrome (OS X v5). Is array.join(”) the fastest way to concat a string. On my test platforms (OS X Firefox, Safari, Opera, Chrome release versions), nope.

Being a public playground, the community benefits from the collective knowledge. Scanning through the test list I saw many of the problems that I have run into before as well as some I had never considered such as the multiple methods of performing a Math.floor operation. While some of these honestly scare me and remind me of Kernel code, it’s good to know they exist.

jsPerf has full support for mobile browsers as well, meaning that you can test performance test the various algorithm options on device and have a realistic view of how it will behave on the device. In running some of the tests on a webOS device there were some quite distinct differences between comparable environments on a desktop class machine.

As with any performance testing I would recommend running these tests multiple times on your target device(s) before selecting a particular path to use as there are many things that could cause a single test to provide inaccurate results for a given execution, particularly on the more resource constrained environments.

Great job Mathias and can’t wait to see what features are added to this as well as the content that the community creates!

1 Comment :, more...

Visit our friends!

A few highly recommended friends...