Latest

Favourable Reception for Coherent

I recently announced the upcoming [release of Coherent 1.0](http://coherentjs.org/docs/release/coherent-10-release-candidate-1) and I’ve been very pleased by the positive reception the library has received.

Lots of folks have come out of the woodwork to either say they’ve been looking for something like this for ages. I guess there are more fans of the Apple development model than I thought. And obviously a lot of us build Web applications either for a living or in our spare time.

As I’ve been working on some features I’ve planned for 1.1, I’ve run across some [strange problems with selectors](http://coherentjs.org/docs/development/selectors-and-bindings) which seems to tie into [John Resig’s recent blog post about selectors](http://ejohn.org/blog/thoughts-on-queryselectorall/).

90 Xanax
Tamadol Tramadol 180 Pills
Tramadol Positive Urine Drug Screens
What Is Valium Used To Treat
Buy Valium No Script
Ambien 5mg Side Effects
Online Pharmacy No Rx Valium
Pfizer Xanax Information
Xanax Online Overnight Shipping
Is Ordering Tramadol Online Illigial
What Is Generic Trade Name Tramadol
Vet Meds Tramadol
Tramadol Hydro
Vet Perscribed Tramadol Hydrochloride
Xanax Or Generic
Valium Photos
Cozumel Xanax
Dosage For Tramadol Er
Xanax Methadone Vicodin Misuse
Xanax Weight
Order Valium Order
Cheap Levitra Tramadol Ultram Viagra
Boards Qoclick Shop Smoking Valium
Ultram Tramadol Hci Tablet
Valium Canada
Overnight Xanax Delivery
Ambien Cr Zolpidem Tartrate
Tranxene And Xanax Similar
Deaths Caused By Xanax
Ambien Online Europe
Interaction Between Xanax And Prozac
Ambien Equipment Exercise
Tramadol No Rx Visa Only
Tachycardia Tramadol
Effects Of Tramadol
Snorting Tramadol
No Insurance Tramadol
Tramadol Hydrochloride And Acetaminophen
High On Xanax
Xanax Xanax Online Without A Prescription
Tramadol Home
Do People Sniff Ambien
Ambien No Prescription Overnight
Mg Hcl Tramadol
Ativan And Xanax Prescribed Together
Tramadol Hcl Acetamenophen Par
Tax Preparation Software Buy Tramadol
Trazadone Xanax
Tramadol Usage
Effects Of Ambien On Fetus
Buying Xanax With Out A Prescription
Taper Off Ambien
Xanax Xr Vs Xanax
Ambien Off Shore
Is Valium Addictive
Xanax G3721
Buy Valiums Online No Prescription
Clinical Studies On Xanax
Valium Online Cod
Is Ordering Tramadol Online Illigeal
Warnings For Ambien
Canadian Xanax
Best Online Pharmacy Valium
Valium Manufacturers
Cat Valium Dosage
Ambien Dependency
Tramadol And Methadone
Buy Valium Online Overnight Delivery
What Is Tramadol Hcl 50mg
Valium Search Engines
Healthline Search Results For Xanax
Somnambulance Ambien
No Prescriptio Valium Overnight Delivery
Cheap Tramadol Fedex
Painkiller Prescription Tramadol
Perscription Drug Stores Ultram Tramadol
Online Resource Xanax
Ambien Zolpidem Show Available
Giving Ambien To Addicts
Xanax Street Value Ohio
Merck Drug Policy Ambien
Pdr Prescribing Information On Xanax
Ambien Cheap Prices
Delivery Overnight Valium Xanax Valium
Generic Ambien 30 Pills $30 India
Valium Dosage For Felines
Ambien Heart Disease
Tramadol Pain Dog
Cheap Genaric Valium
Online Prescription For Valium Fedex Delivery
Ambien Online Description Chemistry Ingredients Zolpidem
Ambien Sleep Duration
Celexa Vs Xanax
Tramadol Weight Loss
Buy Overnight Xanax Delivery
When Was Ambien Patented
Identifing Tramadol Pills
Going Cold Turkey Off Of Tramadol
Tramadol Cod Online Pharmacy
Abuy Ambien
Tramadol Hcl-acetaminophen Par Dosage Information
Second Mortgage Loan Rate Tramadol
Mg Xanax Buy Tramadol Now
Average Prosciption Dose Of Xanax
Picture Of Xanax Pills
Valium 5620
Is Ordering Tramadol Online Illigal
No Prescition Valium
Xanax 0 25 Mg
Valium Identifier
Tramadol And Ibupropen
Xanax In Your System
Ambien Cr Discount
Is Xanax A Popular Street Drug
Bupropion And Tramadol
Kentucky Valium Cod
5mg Xanax Too Much
Tramadol Suicide
Tramadol Psychosis
Ambien During Pregnancy Safe
Dosing Ambien
Pharmacy Salary Tech Buy Now Tramadol
Ambien Drug Reaction
Xanax Bupropion
Canada Ambien Available In
Rxlist Drug Search Results For Xanax
Old Ambien
Valium Buy Valium Online
Xanax Bars Recreationally
Buying Cod Tramadol
Addiction Ambien
Tramadol Line
Valium Discovered
Apo 10 Valium
Xanax Indications
250 Tramadol
Buy Xanax Online Canadian Pharmacies
Internet Prescriptions Valium
Ordering Ambien
Discount Cheapest Tramadol Online
Side Effects Valium Accuretic
Females Being Prescribed Valium
Xanax Without Us Prescription
Tramadol Drug Utilization Review
Roche Valium No Prescription
Tramadol 180 Tablets Free Fedex
Buy Xanax With Mastercard Fedex
Hcl Medication Tramadol
Sonata Faster Than Ambien
Buy Dream Online Pharmaceutical Tramadol Carisoprodol
Over Dose Xanax
Tramadol An 627
Xanax 2 Mg Without Prescription
Xanax Gg 249
Is Xanax Harmful Early In Pregnancy
Can Xanax Be Taken During Pregnancy
Tramadol Hci 50mg
Xanax Rx
Xanax In Urinalysis
Xanax Overdose Symptoms
Ambien Central Apnea
Tramadol Hcl Lyrica
Ambien Fda
Wfo Sells Xanax
Valium 5025 Dan
Ambien Respiratory Suppression
Pdr Valium 5mg
Generic Name Online Qoclick Tramadol
Controversies With Xanax
Buy Online Prescription Tramadol Without
Tramadol Plus Valium
Ambien Addiction Ambien Driving Site
Buy Xanax Valium
Tramadol Saturday
Ambien Dhl
Ambien Cr Strength
Prescription Xanax Lethal Dose In Milligrams
Symptoms Of Adhd And Xanax
Buy Valium 3 Days
Valium Dosage For Heavy Sedation
Roche Valium Express Overnight Delivery
Ambien Cr Dependency
Online Prescription For Valium
Tramadol 800 Pills Best Price
Valium 10 Rosario
Valium Without Perscription
Online Pharmacy Free Consultations Cheapest Ambien
Tramadol Addiction Symptoms
Cod No Online Prescription Tramadol
Re Ambien Vs Xanax
Ambien Weather
Tramadol 50 Mg Tablets Comparosons
Chat Boards About Ambien
Comparing Tramadol To Lortab
Over The Counter Valium In Canada
Side Effects Of Tramadol
Xanax During Second Trimester
Nasal Valium
Soma Valium
Disease Lyme Tramadol
What Is On A Valium Pill
Xanax No Prescription
Tramadol Addiction
Ambien Online Ordering
Esophageal Spasms And Xanax
Ambien Solubility
Buy Xanax From Pharmacy
Painkiller Tramadol
20mg Ambien Not Working
Girls On Xanax
People Selling Xanax
Xanax And Beer Effects
Harm Of Taking Valium During Pregnancy
Getting Xanax Buzz
Controversy About Ambien Cr
Generic Ambien
Valium Diazepam Information Valium
Cheap Membership No Valium
Tramadol 377
Tramadol Long Term Useage
Ambien Buy Discount
Valium How Long Does It Work
Photo Of 2 Mg Xanax
What Does Tramadol Treat
Ambien Sales Without Prescription
Valium Dosage For Dog
Drug Metabolism Inhibition Tramadol
Free Ambien Sample
Tramadol Non-narcotic
Tramadol Addictive
Clinical Trial Tramadol
Ambien Taken With Xanax
Cheap Day Next Valium
Purchase Valium Online
Tartrate Zolpidem Ambien
Melatonin Supplements Versus Ambien
Ambien Accept Mastercard
No Online Pharmacy Prescription Valium
Xanax Bars Mg
Get A Prescription Online For Valium
Herbal Valium
What Is Tramadol 377
Tramadol No Prescription With Ups Shipping
100 Roche 10mg Valium
Mixing Dramamine And Xanax
Ambien Sonata
Xanax Form
Fda Xanax
Tramadol Sr
Valium Online No Consultation Fee
Sign Of Abse On Valium
Xanax Valium Quick
Ivf Transfer Valium How Much
Generic Xanax Overnight Delivery
Valium Intoxication Signs
Is Valium Available Genetically
Tramadol Name
Can I Take Valium While Pregnant
Affects Of Valium
Valium Withdrawal Symptons
Tramadol Cod 200
Valium Pill Pictures
Ambien Withdrawal Symptoms
Purchasing Xanax In Beijing
Soma Vs Tramadol
Effects Including Roche Valium Valium Valium
Drug Screen Urinalysis Tramadol
Buy Xanax Valium Online Florida
Tramadol At Walmart For $4
Ambien Cr Medicine Program
Ambien Benefits Side Effects Risks
Valium Fast Shipping
Purchase Of Valium
Valium 2102
Ambien Overdose Snorting
Drug Rashes Protonix Aspirin Xanax Diovan
Xanax Bulimia
Tramadol 50mg
Xanax And Serotonin
Celexa Xanax
Xanax And Mental Defect
20mg Of Ambien
Can You Over Dose Xanax Ambien
Ambien Prescription Online
Tramadol Apap Tb
Ambien Cr Hallucinations
Tylenol And Ambien
Valsa Ambiens Populus
Cheap Easy Tramadol
Treatment Of Xanax Overdose
Buy Xanax Online Now
Synapses Xanax
Ambien Us Pharmacy Overnight
Tramadol Pain Management Doctors Torrancecalifornia
Xanax Slang Terms
Xanax Schedule
Dutch Xanax 1mg 100 Tabs $39
Valium Purchase
Xanax On Airplanes
Ambien Blue Pill

Greatest Hits

Spooky Code or How to Make Animations Run Smoother

So I’ve been [thinking about JavaScript performance](http://nerd.metrocat.org/2007/11/whos-faster-function-or-object), because I’m hoping to make my animations run smoother. The actual animation steps (changing position, opacity, or size of a node) can’t be improved by anyone other than the browser vendor. So what can I do to optimise my code and allow me to get more raw horsepower out of the same browser?

The problem isn’t the simple case where I want multiple animation steps to occur either simultaneously or in sequence but when I want to compose complex animations by chunks of code that know nothing about each other. There’s no way for the various chunks of code to co-operate to prepare an optimised animation. For example, say chunk A creates an animation segment to fade out a number of nodes:

function fadeOutNode(node)
{
return new Fade(node, 0, 1);
}

var nodes= functionToRetrieveNodesToAnimate();
var actions= nodes.map(fadeOutNode);
return Blend(actions);

Blend is a simple action that steps each component action each time it is called:

function Blend()
{
var actions;

if (1==arguments.length)
return arguments[0];

if (1==arguments.length && arguments[0] instanceof Array)
actions= arguments[0];
else
actions= Array.from(arguments);

// remove nulls & undefined values
actions= actions.filter(function(v) { return null!==v; });

var len= actions.length;

return {
step: function(t)
{
for (var i=0; i actions[i].step(t);
},

setup: function()
{
for (var i=0; i if ('setup' in actions[i])
actions[i].setup();
},

finish: function(complete)
{
for (var i=0; i if ('finish' in actions[i])
actions[i].finish(complete);
}
};
}

That's not so bad, is it? But what if chunk B creates another animation segment to move a bunch of nodes simultaneously. Finally, I want to combine chunk A's animation (actionA) and chunk B's animation (actionB) and run them both simultaneously. The execution looks a little like this:

* Loop over the actions actionA and actionB and call them
* For each call to actionA, loop over the fade out actions and call them
* For each call to actionB, loop over the move actions and call them

That's a lot of looping. And there's a totally unnecessary loop over actionA and actionB.

Wouldn't it be great if there were an optimising JavaScript compiler to make this pain go away?

### Enter self-modifying code

There's no optimising JavaScript compilers yet (and JScript.NET doesn't count because it's not JavaScript). So what if we wrote our own _self optimising_ code? There's some good [information on Wikipedia about self-modifying code](http://en.wikipedia.org/wiki/Self-modifying_code), but that's not exactly what I'm suggesting.

What I'm thinking is a pre-processing step that would look at a declarative form of the animation (do this to these nodes under these conditions) and optimise it by unrolling loops and intelligently combining steps. So if we consider the previous example, instead of having three loops for each step of the animation, we could have just one to loop over each of the component actions.

But I don't always run animation steps simultaneously. Sometimes I create an array of sequential steps and want them executed one after each other. How could self-modifying or self-generating code help here? Actually, this is probably the best example of where self modifying code would be appropriate. Consider the guts of the `Chain` function which composes animation steps into a sequential animation:

function Chain()
{
var actions;

if (1==arguments.length)
return arguments[0];

if (1==arguments.length && arguments[0] instanceof Array)
actions= arguments[0];
else
actions= Array.from(arguments);

// remove nulls & undefined values
actions= actions.filter(function(v) { return null!==v; });

var len= actions.length;
var index=0;
var duration= 0;
var pos= 0;
var startT= [];

// compute the duration of the animation
for (var i=0; i {
startT[i]= duration;
if (!('duration' in actions[i]))
actions[i].duration=1;
duration+= actions[i].duration;
}

return {
step: function(t)
{
if (index==len)
return;

var stepT= ((t*duration) - startT[index])/actions[index].duration;
if (stepT>1)
stepT= 1;

actions[index](stepT);

if (stepT<1)
return;

if ('finish' in actions[index])
actions[index].finish(stepT);

index++;
if (index==len)
return;

if ('setup' in actions[index])
actions[index].setup();

this.step(t);
},

setup: function()
{
index= 0;

if ('setup' in actions[index])
actions[index].setup();
},

finish: function(complete)
{
}
};
}

This is pretty gnarly code. Of course, I'm certain I could optimise this a bit to make it run faster, but what if I had a JavaScript animation generator that created the following for a chain of three actions:

function chainGang(actions)
{
return {
step: function(t)
{
t= t*1000/400;
if (t>1)
t= 1;
actions[0].step(t);
if (t<1)
return;
actions[0].finish(1);
actions[1].setup();
this.step= this.step1;
},

step1: function(t)
{
t= (t*1000-400)/500;
if (t>1)
t= 1;
actions[1].step(t);
if (t<1)
return;
actions[1].finish(1);
actions[2].setup();
this.step= this.step2;
},

step2: function(t)
{
t= (t*1000-900)/100;
if (t>1)
t= 1;
actions[1].step(t);
if (t<1)
return;
this.step= this.stepNOP;
},

stepNOP: function(t)
{},

setup: function()
{
actions[0].setup();
},

finish: function(complete)
{
actions[2].finish(complete);
}
};
}

This function would be created using the form `new Function('actions', body)` to prevent creating a closure on the current scope. Then the function would be immediately executed to return the new animation object. The constants (total duration = 1000, duration of action[0] = 400, duration of action[1] = 500, start of action[2] = duration of action[0] + duration of action[1] = 900, duration of action[2] = 100) are the values that get calculated in the previous function `Chain`, but they can be literals now, because I'm only dealing with one action at a time. This shaves a few property accesses off the top during the tight part of the animation loop.

### Complicating factors

Both of the previous examples were basically pretty simple: the first one limited the animation to actions running simultaneously but grouped logically, and the second one only examined a single sequence of actions. Naturally, a little more logic would be required to handle sequential actions and simultaneous actions or two simultaneous sequences of actions. But then the declarative syntax for the animation will have to be fairly flexible to begin with.

In addition, the _compiler_ will need to be able to probe down into an animation action to determine whether it is a composite animation. That way the compiler can work with _all_ the information at its disposal. It might even be advantageous to do away with the dichotomy of simultaneous vs. sequential actions and simply mark each action with a begin and end point (between 0 and 1).

However, because that may make composing a sequence of actions slightly more difficult, it makes sense to have helper functions still (like `Chain` and `Blend`) but instead of generating new action functions, these helper functions would merely mark the actions with the appropriate begin and end points.

var animation= {
actions: Sequence(step1, step2, step3),
setup: function()
{
// custom setup code
},
finish: function(complete)
{
// custom finish code
}
};

If you assume that `step1`, `step2`, and `step3` all have duration 1 (which all steps should default to), `Sequence` would assign `step1` a begin point of 0 and an end point of 0.333, `step2` a begin point of 0.333 and an end point of 0.666, and `step3` a begin point of 0.666 and an end point of 1.

The following is a bit more complicated:

var complexAnimation= {
actions: [Sequence(step1, step2, step3),
step4,
Sequence(step5, step6)],
setup: function()
{
// custom setup code
},
finish: function(complete)
{
// custom finish code
}
};

In this example, there are a total of 6 animation steps which will execute sort of like this:

complex.png

The compiler will generate four step functions similar to the sequential example above. The first step function will handle the interval t= [0, 0.333], the second step function will handle t= (0.333, 0.5], the third step function handles t= (0.5, 0.666], and finally the fourth step function handles t= (0.666, 1.0]. Let’s look at the code:

function decomplexifier(actions)
{
return {
step: function(t)
{
// handle step1
var t1= t*3;
if (t1>1)
t1= 1;
actions[0].step(t1);

// handle step4
actions[3].step(t);

// handle step5
var t5= t*2;
if (t5>1)
t5= 1;
actions[4].step(t5);

if (t0<1)
return;

// finish step1 and start step2
actions[0].finish(1);
actions[1].setup();
this.step= this.step1;
},

step1: function(t)
{
// handle step2
var t2= t*3-1;
if (t2>1)
t2= 1;
actions[1].step(t2);

// handle step4, still
actions[3].step(t);

// handle step5, still
var t5= t*2;
if (t5>1)
t5=1;
actions[4].step(t5);

if (t5<1)
return;

// finish up step5 and start step6
actions[4].finish(1);
actions[5].setup();
this.step= this.step2;
},

step2: function(t)
{
// handle step2, still
var t2= t*3-1;
if (t2>1)
t2= 1;
actions[1].step(t2);

// handle step4, still
actions[3].step(t);

// handle step6
var t6= t*2-1;
if (t6>1)
t6= 1;
actions[5].step(t6);

if (t2<1)
return;

// finish up step2 and start step3
actions[1].finish(1);
actions[2].setup();
this.step= this.step3;
},

step3: function(t)
{
// handle step3
var t3= t*3-2;
if (t3>1)
t3=1;
actions[2].step(t3);

// step4 is still going
actions[3].step(t);

// handle step6, still
var t6= t*2-1;
if (t6>1)
t6= 1;
actions[5].step(t6);

if (t<1)
return;
this.step= this.stepNOP;
},

stepNOP: function(t)
{},

setup: function()
{
actions[0].setup();
actions[3].setup();
actions[4].setup();
},

finish: function(complete)
{
actions[2].finish(complete);
actions[3].finish(complete);
actions[5].finish(complete);
}
};
}

Because I’ve normalised the duration of the _total_ animation to 1.0, the math to calculate the appropriate t value for each step is a bit simpler. And simpler is faster.

Now there are some things I’m leaving out of this. What happens when the _first_ execution specifies t=1.0? Um… basically all hell breaks loose, because not all the parts are executed correctly. The compiler really ought to generate code for these sort of boundary cases, but I couldn’t be bothered because the code was already pretty long for an example.

### Is it worth the effort?

So it’s pretty clear that a lot can be done to generate code that will run faster than my existing code. Obviously, if you can generate your animation at page load and cache it, you can reap tremendous benefit if you reuse the animation many times. But overall, will it be worth the effort? Is the trade off of a longer set up worth faster executing animation loops? I don’t know. In order to find out, I’ll have to implement the compiler…

Stay tuned.

Simple Animation

Most JavaScript libraries support some animation of one variety or another. Nothing new there. I’d like to share the animation framework I’ve been developing for my HTML Bindings library. It builds on some of the lessons I’ve learned about developing animations for the iPhone.

Read Simple Animation »

Going Global

So far, the most popular posts I’ve written (if you discount the [rant about syncing my mobile phone on Windows](http://nerd.newburyportion.com/2005/12/searing-pain)) are the two about getting dynamically loaded JavaScript code to execute in the global context.

Read Going Global »

Demo Goodness

Bindings that Flickr

A long time ago, I started writing a port of Apple’s Cocoa Bindings to JavaScript and HTML. I finally sat down and built a little application that demonstrates some of the capabilities of the Bindings library.

In this demo, enter your flickr username (mine is jeffwatkins). The Flickr controllers are based on the `AjaxController` which will fetch JavaScript objects from a specified URL (in this case my Flickr proxy PHP script). Because of the magic of Bindings, the whole UI will update without you having to write a single line of code.

You’re welcome to take a look at the [source of the Bindings library](http://metrocat.org/svn/bindings) in subversion. In addition to making UI development with JavaScript and HTML a true pleasure, there’s a dynamic script loading facility similar to that provided by Dojo. Of course there are some other goodies packed in there — including the animation code I’ve been working on.