OZONE Asylum
Forums
DHTML/Javascript
Optimising JavaScript loops
This page's ID:
29314
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
Might as well take a chance to jump in, so hello, world. I think it all deserves a few updates - clearly, the tips are good (well, the ones which haven't been removed), but all things evolve. Language independent trick (1) for optimisation, get your algorithms rights. Eg. look them up. Some fields of algorithm research are broadly open, like 3d compression and the likes. Some have been explored in and out, and (almost) all recipes exposed. Get the available ones, and the fastest ones. look up stuff you want to do and append " algorithm" at the end of your query. For "lower level languages", like Cpp or Assembler, then, there are some truths to be used : comparisons to 0 always are faster (hence the --x > 0 kind of loop). Most architectures like integer based operations, some are optimised for floats. MOD operator is slow. Divide is quite slow too. Mult, plus, minus, are fast, in floating point or integer. Numbers that are powers of two are useful when coding, because they allow easy bit shifting. Instead of number / 2, you can do number >> 1 (bit shift that right). Part of this, actually, most of what is arithmetic optimisation and what affects loops and comparisons, remains true for higher level languages, like Java or Javascript, semi-interpreted and interpreted But for both Java and Javascript, other kinds of optimisations must be considered, which are HIGHLY dependent on the implementation. See poi's 3d Tomb II about that. The underlying memory management, namely, matters a lot : the case of closures in javascript is a dangerous example. It is easy, in js, to create cyclic references that mess up garbage collection. This impacts speed also because a lot of adressed memory is more difficult to manage to a given runtime environment (than only a few kbs or megs). And then there is size optimisation, a whole different topic altogether, yet tightly related... less instructions seemingly lead to faster results, but this is not a rule of thumb, it is a general condition with exceptions. Sample exception : if you create lookup tables for sine and cosine operations, sine and cosine operations will be faster, but creating lookup tables may result in a larger executable. Faster, but larger. For Javascript only, you can : 1) safely apply the maths and conditions and loops tricks. 2) safely apply many size optimisations, like variables obfuscation. And you should : 3) Watch out for the structure of the target documents, large dom, small dom? Inline CSS? (that is the devil) Can you alter classes at once, or should you focus on named elements? It all depends on what you want to do.
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »