Activate your free membership today | Log-in

Thursday, December 22nd, 2005

JavaScript Performance: Comparing the Atlas and Prototype class idioms

Category: .NET, JavaScript, Prototype

Firstly, it has to be said that micro-benchmarks are the root of all evil.

Now that is out of the way, Jon Meyer took the time to compare styles of subclassing in JavaScript, based on what he sees in Prototype and Atlas.

He analyzes performance implications, giving numbers, and it allows you to see differences between the browsers (well, FF/IE).

Conclusion

In both approaches, there is a penalty for subclassing, especially on IE.

For a performance-critical class, set frequently accessed properties/methods directly on the this instance rather than placing them further up the prototype chain.

The Prototype idiom, generally speaking, produces code that runs marginally slower on IE, when doing general-case method/property access.

The Atlas idiom has the benefit of truly “private” instance variables – you can use closures to define variables that are only visible within a specific method. There appears to be no perf penality for accessing/updating these closure variables.

A major drawback of the Atlas approach is that constructing instances takes much longer. For a class where thousands of instances are constructed (e.g. a IsoDate class), this is a significant issue. For a class that is constructed once and lives the lifetime of the app, this may not be an issue.

The functional iterators of Prototype perform slowly compared to for loops.

Posted by Dion Almaer at 9:56 am
2 Comments

+++--
3.2 rating from 15 votes

2 Comments »

Comments feed

This is a frustrating comparison.

It appears to have been run inside a browser and not in the command line interpreters for each engine and so is not well isolated.

I’m also not sure that it covers any of the important debates about writing quick code in a JS interpreter. The amount of time it takes to instantiate a class is a *pittance* compared to the memory cost difference between the tested approaches, and neither seem to actually hit the linearly-increasing object allocation speed issue on IE.

In short, it’s a blind benchmark of the wrong attributes of the wrong idioms. DOM performance, regexp speed, string manipulation, and memory size stats actually matter since they dwarf object instantiation cost. I’m afraid that this set of tests is merely a distraction.

Regards

Comment by Alex Russell — December 23, 2005

tiffany rings tiffany rings
tiffany engagement rings tiffany engagement rings
tiffany wedding rings tiffany wedding rings
tiffany necklace tiffany necklace
tiffany sets tiffany sets
tiffany bracelet tiffany bracelet
tiffany pendant tiffany pendant
tiffany earrings tiffany earrings
tiffany accessories tiffany accessories
tiffany charms tiffany charms
Abercrombie Jeans Abercrombie Jeans
Abercrombie Pants Abercrombie Pants
Abercrombie Tees Abercrombie Tees
Abercrombie Shorts Abercrombie Shorts
Abercrombie Sweater Abercrombie Sweater
Abercrombie Outerwear Abercrombie Outerwear
Abercrombie Hoodies Abercrombie Hoodies
Abercrombie Polo Abercrombie Polo
Abercrombie ShirtsAbercrombie Shirts
abercrombie henleys crew abercrombie henleys crew
hollister hollister
hollister uk hollister uk
abercrombie mens abercrombie mens
abercrombie womens abercrombie womens
Ruehl 925 Ruehl 925
ed hardy ed hardy
shamwow shamwow
nest match nest match

Comment by jenny625 — March 16, 2010

Leave a comment

You must be logged in to post a comment.