Skip to content

Instantly share code, notes, and snippets.

// === Identifier rewriting for the ES6 module transpiler ===
// Proposal for minifier-friendly ES6 module transpiler output.
// This is for cases where we don't require any existing module
// format (AMD, CommonJS) and just want to emit a blackbox IIFE
// that uses modules internally. Those cases are Ember's normal
// global distribution (ember.min.js), as well as ES5 generated
// by the upcoming ember-cli ES6 stack.
// Do you all think this could work?
~3607 bytes min.gz overhead from these kinds of declarations:
define('somemod', ...
...
var rewatch = __dependency6__.rewatch; <-------------
var finishChains = __dependency7__.finishChains; <-------------
...
There are 793 such lines, thus adding about 4.5 bytes in .min.gz size each.
#!/bin/bash
(
echo "(function() {"
for i in {0..9999}; do
echo "
var var$i = 1
var read$i = function() {
// Prevent inlining by feigning recursion
if (!var$i) read$i()
var outerVars = 10000
var iterations = 100000
src = ''
src += '(function() {'
for (var i = 0; i < outerVars / 3; i++) {
src += ' var num' + i + ' = 1\n'
src += ' var read' + i + ' = function() {\n'
// Prevent inlining by feigning recursion
src += ' if (!num' + i + ') read' + i + '()\n'
#!/usr/bin/env node
var fs = require('fs')
var rimraf = require('rimraf')
fs.mkdirSync('x')
var string = ''
for (var i = 0; i < 100; i++) {
string += '1234567890'
@joliss
joliss / Source.coffee
Last active August 29, 2015 13:57
Emitting Sprockets require with CoffeeScript
###
*= require jquery
*= require underscore
###
fs.mkdirSync('testdir')
var obj = {
'foo.txt': 'foo.txt contents',
'subdir': {
'bar.txt': 'bar.txt contents',
}
}
writeSync('testdir', obj) // write foo.txt and subdir/bar.txt to disk
[broccoli-filter] Copy time in TranspilerFilter: 23ms
[broccoli-filter] Copy time in TranspilerFilter: 111ms <--------
Slowest Trees | Total
-------------------------------+----------------
TranspilerFilter | 204ms <--------- probably this one - 50%?
Concat | 117ms
TreeMerger | 114ms
TreeMerger | 105ms
@joliss
joliss / optimizing.md
Last active August 29, 2015 14:01
Broccoli-filter: where we're spending time on no-op rebuild
  • helpers.copyPreserveSync (would need API change to do symlinks instead; possibly still optimizable without symlinks)
  • walkSync
  • helpers.hashTree (note: also duplicates stat calls with walkSync)
  • mkdir/mkdirp (probably unnecessary calls here)
  • rimraf via quick-temp via broccoli-writer (new API would move this from writer into core, but rimraf call is still necessary)
  • perhaps some suprising CPU sinks, like hashing crypto, path module, etc.
@joliss
joliss / gist:73804f5c8efa262c0b7d
Last active August 29, 2015 14:02
Optimizing merge-trees

Breaking down what merge-trees spends time on, on a set of 500 small files:

walkSync 6 ms
pathManipulation 7 ms      <------- string stuff, doesn't hit file system
mkdir 1 ms
copy 71 ms     <------- clearly unacceptable, and gets much worse with big image files
mergeTotal 86 ms