Thursday, 21 October 2010

Optimising jQuery each

Yea, another optimisation post, it's not an obsession, it's just this is pretty interesting. Jamie Stewart tweeted about this article on optimising jQuery each. I really like the idea of creating an empty jQuery object and passing context to it - it just seems smart. I'm always wary of optimising prematurely though so I wrote a little speed test page of my own. You can run the tests yourself, and then come back and comment :).

The results of which seem to show to me that whilst the optimisation is faster, it's probably not going to be noticeably faster in my day to day usage. Still, faster is faster, right? Well, not always, I would see using this as a standard replacement for .each as a premature optimisation. Whilst it is faster, it's not no-brainer faster; there are other factors to consider:
  • The optimisation comes in plugin form, which is extra code to download and possibly an additional http request

  • Breaking from jQuery core means a possible break from future jQuery optimisations

  • Faster, IMHO in this case, doesn't trump readability
I would definitely consider this method for large iterations and when I know something is slow, but it won't become my go to replacement for .each - despite how cool an idea it is.

Monday, 4 October 2010

Web blasphemy

A while ago Andrew Donaldson wrote an interesting article on how "gut reactions" to things in web development can actually close our eyes to new ideas (in which he brutally mangles my approach to CSS :-)). I think the key point in our discussions is summed up nicely: "When discussing the presentation with my friends I remember saying 'I don’t know why I don’t like it, but I just don’t'".

This week I was watching Julien Lecomte's awesome talk on high performance ajax which touches on this subject which a worthy example. He is talking about breaking a small rule for a big payoff and mentioned replacing span class="bold" with the deprecated b element to make a big file size saving (in his example where displaying perhaps 1000 results).

I found myself immediately thinking "well, surely you'd page the results and so the saving would be dramatically lessened". Which, of course, is not relevant to the point being made, but was a knee jerk reaction on my part to the blasphemy of using deprecated elements! It made me think of how many other possible savings or great ideas I'd missed because my standards advocacy had placed me firmly back inside the box.

Friday, 1 October 2010

Look on my works, ye mighty, and despair!

I've been doing a lot of yoga recently, which I'm really enjoying. Unfortunately, being the least flexible person on the planet I manage to both suck and blow simultaneously at yoga. I'm also running twice a week, which is a trial... Since I hurt my back, my gait has shortened and it takes forever to run anywhere.

So it was nice to be in the gym today and actually do something well. 5 sets of 5 reps on the bench with 120kg supersetted with weighted pullups:
  • 7 reps warm up
  • 8 reps with 5kg additional weight
  • 6 reps with 10kg additional weight
  • 5 reps with 15kg
  • 5 reps with 15kg
  • 4 reps with 20kg
Then some triceps to finish off. It was a good day :)