About javascript optimization

There are lots of rules to optimize the loading of javascript, I will try to list some of them (at least, the ones I try).

The golden rule here is always to test every optimization you make, using jsperf for the simpler, and setting up abtests for the most complex scenarios.

Social GPS: Waze

Raramente ho fatto recensioni o pubblicità a programmi: questa la scrivo perché il software, la app, merita e perché essendo una cosa social, più gente la usa e meglio diventa.

Waze è alla fine semplicemente un navigatore satellitare; la questione social si traduce nei punti e nei livelli di esperienza (poco interessante) e nelle segnalazioni: Tom Tom fa pagare a parte l’aggiornamento degli autovelox e delle mappe, su Waze no è tutto splendidamente scaricato al volo. Da un iPad si scaricano circa 6 mb di informazioni sulla tratta Imperia – Bologna (350km circa).

È ottimo se usato da un passeggero, che oltre a consultare le strade e aggiornarlo può chattare con gli altri wazers nelle vicinanze, è un po’ scomodo se si viaggia da soli dato che dipende dai supporti per auto per iPad o iPhone, io non ne ho ancora trovato uno soddisfacente.

 

Insomma: provatelo.

 

aggiornamenti

E’ da tanto tempo che non scrivo qua. Sono successe un sacco di cose, e da un po’ ho smesso di lavorare esclusivamente con Actionscript. Ho deciso prolungare la vita di questo blog, e di rinnovarlo seguendo le mie ultime passioni e tendenze. Innanzi tutto la lingua: sto scrivendo in italiano, il motivo è che per quanto voglia migliorare il mio inglese mi viene molto più naturale scrivere in italiano e siccome la voglia di scrivere va e viene, meglio non ammazzarla perdendo tempo.

About Flash Optimization

Working with flash and actionscript I often stumble upon bad and slow code (either old code of mine or written by others – designers); In this post I’ll try to list some resources worth knowing if you want to write fast and nice code.

Best Practices

  1. Do not use Objects, if you know which properties will be finally involved: dynamic properties are slow to read. Create custom classes instead.
  2. Strong type everything. If you think there is a reason to avoid strong typing, at least use * as type.
  3. Try out and test different strategies with Grant Skinner’s performance framework.

Resources

Feel free to suggest more :-)

Quickreference: flipping DisplayObjects

This one flips DisplayObjects on a vertical or horizontal axe.

public static function flipHorizontal(obj:DisplayObject):void {
    var m:Matrix = obj.transform.matrix;
    m.transformPoint(new Point(obj.width * .5, obj.height * .5));
    m.tx = (m.a > 0)?obj.width + obj.x:obj.x - obj.width;         
    m.a = -1 * m.a;
    obj.transform.matrix = m;
}
       
public static function flipVertical(obj:DisplayObject):void {
    var m:Matrix = obj.transform.matrix;
    m.transformPoint(new Point(obj.width * .5, obj.height * .5));
    m.ty = (m.d > 0)?obj.y + obj.height:obj.y - obj.height;
    m.d = -1 * m.d;
    obj.transform.matrix = m;
}