jQuery’s .data() Method Is Ridiculously Slow.

| Comments

I was having an issue where jQuery’s .data() seemed extremely slow in a particular scenario. I ran benchmarks for .data(), .attr() and .getAttribute() which essentially all do the same thing and the results were astonishing.

In Chrome 20 and Firefox 13.0.1 running on my 2009 iMac, 10,000 runs on a single element gave me the following results:

Method Chrome Firefox
.data() 74ms 148ms
.attr() 16ms 76ms
.getAttribute() 1ms 3ms
.data() invalid attribute 117ms 179ms
.attr() invalid attribute 22ms 71ms
.getAttribute() invalid attribute 1ms 3ms

It seems like .data() is about 30-40% slower when the attribute does not exist.

The code I used for this first test is here: https://gist.github.com/3182945

.getAttribute() seemed a bit too fast so I wondered if my benchmarks were wrong or flawed because I was constantly fetching the data of the same element. I decided to rewrite my benchmarking code to actually loop a 10,000-element DOM, which is more realistic. Here are my results:

Method Chrome Firefox
.data() 198ms 403ms
.attr() 31ms 113ms
.getAttribute() 1ms 5ms
.data() invalid attribute 133ms 232ms
.attr() invalid attribute 25ms 106ms
.getAttribute() invalid attribute 3ms 5ms

It looks like my first benchmarks were pretty much representative of the reality. We get the same kind of performance gap over a large DOM.

The code for this second test is here: https://gist.github.com/3183364

It’d be interesting to see how other browsers compare…

The End of an Era

| Comments

I’ve been feeling sad and nostalgic lately. I have come to realize that it is the end of an era for the Montreal tech community.

On February 17 2007, I attended the very first  Montreal Tech Entrepreneur breakfast organized by then unknown (at least by me) Ben Yoskovitz. I admit that I did not expect much from that event. After all, I had just returned from a long stay in Silicon Valley where the tech scene is ridiculously active. I had left for the Valley because Montreal’s startup scene was simply nonexistent; I was looking for my next move after selling my first company.

That morning of 2007 turned out to be the cornerstone of the Montreal Startup Scene as we know it today. If you weren’t there, you’re probably frowning at this point, but many of the attendees believe this to be true as well. For the first time in our lives, we realized we were not alone: other Montrealers had startup ambitions. I remember meeting Sylvain Carle, Ben Yoskovitz, Patrick Tanguay for the first time, and Fred Ngo for the second time. I had met Fred a week or so before moving to the Valley. He was still working at Matrox at that point and didn’t think he had the balls to play the Startups Game. (sorry :) )

All of us were looking for our next move. And boy did we move! We ended up starting the city’s very first batch of  startups all at the same time. The landscape then looked like this:

  • Defensio (myself, Mat Balez, Camilo Lopez)

  • Standout Jobs (Ben Yoskovitz & Fred Ngo)

  • Praized (Sylvain Carle & Sebastien Provencher)

  • SmartHippo (George Favvas)

  • Station C (co-working, Patrick Tanguay)

Tech events such as BarCamp, DemoCamp and Montreal on Rails also popped up shortly after. (if it has the word Camp in it, chances are Sylvain organized it!)

Fast forward 5 years, Defensio and Standout Jobs have been sold, Praized is now Needium under new management, SmartHippo folded and Station C is still going strong.

So why am I feeling sad and nostalgic? Out of these 8 people, 8 friends, 6 have already left Montreal, and I know more are about to. Mat Balez has been working at Google in London, and now in Mountain View for a while, Fred has been in Vancouver for a couple of years, Camilo just moved to Ottawa and works at Shopify, George is working on his new startup Rewardli in San Francisco, Ben just moved to Halifax to work at GoInstant, a co-browsing service, and Sylvain just moved to San Francisco as well to work at Twitter. All these people were instrumental in the birth of the local startup scene. Ben and Sylvain pioneered it.

I can’t help but feel sad to see all these friends leaving. But I understand. I would have done the same.

Farewell friends. I sincerely wish you the best of luck on your new adventures!

Defensio: A Short History (Repost)

| Comments

This is an old favorite of mine. I am re-posting this here in fear that it will eventually disappear off the Websense Security Labs blog. Original from July 9 2007 is here. Enjoy!

The original Karabunga (Defensio) teamThe Defensio story begins not-so-long ago with our team looking at the web ecosystem and thinking about those nagging problems that have yet to be satisfactorily resolved. One of the first and most annoying that jumped to mind was spam. As we all know, spam is a scourge that mercilessly plagues our e-mail inboxes. But spam has also crept up on us in the blogosphere: slowly at first, and then exponentially of late, comment spam has begun, much to our collective chagrin, to inundate our blogs like a tidal wave of smelly, post-processed meat sledge.

Vowing to take on the multi-headed beast that is blog spam, the Defensio team set up shop in an old tobacco factory outside of Montreal, plugged in our laptops to large monitors, and started writing spam-shredding Ruby on Rails code. And because no Silicon Valley Eastern-Township startup would be complete without free pop and nerdy games of skill, we rounded out the office space with a fridge and a ping-pong table.

… time passes, much diet pepsi and pizza is consumed …]

After months of R&D, the Defensio blog spam filter was nearing launch-ready state. Encouraging results on our internal testbed prompted us to solicit a few brave local souls (infinite thanks to Julien, Ben and Pat) to run our alpha code on their very own blogs. As we worked out the kinks in the code, we realized that our newborn nameless app urgently needed to be christened with a brand that screamed “spam’s worst nightmare”. Many brainstorming sessions and many terrible candidate names later (mZego anyone?) our shiny new monicker came to light: DEFENSIO. Strong. Dependable. Spam-aint-gettin-through. Perfect? Yes, but one problem: the domain name was in that murky state known as “redemption period”.

We can admit to some sleepless nights as we watched the domain status incessantly. Being the uber-geeks that we are, we wrote a script that polled the WHOIS server every hour and would notify us of a change in state. Eventually, the name became poised for deletion, but it would not be ours until we were dragged into the slimy, wet mud of a bidding war with a shadowy character named ‘halvarez’, who had a reputation for sniping domain names at the very last second - a formidable opponent, to say the least. Fortunately though, our steely nerves saw us through this online game of chicken, and we prevailed, defensio.com in hand.

Which brings us to the present. Our web-service is now nearing launch ready state, already smoking many thousands of spam comments every day, under the Defensio banner we all so love.

Yet, this is but the beginning of what is sure to be a long, protracted war. As spammers don’t sleep, nor will we.

Major props to Camilo Lopez and Mat Balez for making all this happen!