Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
MochiKit.DOM.getElementsByTagA ndClassName performance
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
takashi mizohata  
View profile  
 More options Nov 3, 5:23 pm
From: takashi mizohata <bea...@gmail.com>
Date: Tue, 3 Nov 2009 17:23:09 -0500
Local: Tues, Nov 3 2009 5:23 pm
Subject: MochiKit.DOM.getElementsByTagAndClassNam e performance

Hi All,

Forgive me, if this is a recurring argument.

Today I was looking at Firebug profiler and I realize that
getElementsByTagAndClassName takes certain percentages of processing
time.  And I took a look at the code, and I did a little bit of hand
optimization.  It doesn't change any semantics of code, but just
organizing code.  It does pass the tests of course.  And i got around
6% better performance.

Well the down side of this tweak may be the decrease of readability.
Since you need to carefully type comma between local variables.  I
usually check it with jslint before commit in order to find those
potential mistakes.  And obviously I don't much about coding
convention of MochiKit and I might need to edit the style of it.

Here I attached .patch file for this issue.  Please try it and let me
know what you think. if somebody's interested in, I can contribute
some more performance tweaks in MochiKit.

Thanks,

--
Takashi M

  getElementsByTagAndClassName.patch
2K Download

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Per Cederberg  
View profile  
 More options Nov 4, 2:14 am
From: Per Cederberg <cederb...@gmail.com>
Date: Wed, 4 Nov 2009 08:14:04 +0100
Local: Wed, Nov 4 2009 2:14 am
Subject: Re: [mochikit] MochiKit.DOM.getElementsByTagAndClassNam e performance
Generally, I think some of these optimizations make sense. Like using
"===" instead of "==" in code like this:

   typeof(x) === "string"

But I think the optimizations where variables are moved outside code
blocks and where array lengths are stored to variables should be used
with extreme caution. These are the type of things that people used to
recommend for Java code, but nowadays the virtual machines optimize
these things better by themselves. And what used to be a speedup
actually often leads to decreased performance.

For JavaScript, the VM:s are much more immature. But they are rapidly
becoming faster and more advanced. So low-level code optimizations
that result in a speedup today, might not do so just a year or two
down the road.

I think our focus here should be on clarity of intention. If some
critical-path function is extremely slow, we might want to have a look
at optimizing that specific function. But in general I think we should
refrain from low-level code optimizations that doesn't also improve
code readabilty and reduce the frequency of bugs.

Also, if speed is a problem, most serious speedups come from changes
to the algorithms and data structures involved. In this case for
instance, it might be faster to first find elements by class and then
filter out the ones with the correct tag. Or by using an
indexOf("class") on the className field before splitting it up. These
kind of optimizations will probably result in higher gains with less
reduction to the code readability.

Just my 2 cents.

Cheers,

/Per


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bob Ippolito  
View profile  
 More options Nov 4, 11:22 am
From: Bob Ippolito <b...@redivi.com>
Date: Wed, 4 Nov 2009 08:22:12 -0800
Local: Wed, Nov 4 2009 11:22 am
Subject: Re: [mochikit] Re: MochiKit.DOM.getElementsByTagAndClassNam e performance
At least with recent browsers there are better ways to speed this up,
e.g. by leveraging more native code (getElementsByClassName and/or
XPath). None of them did this when the code was written in 2005 but I
think all of them do now (except maybe IE).


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Amit Mendapara  
View profile  
 More options Nov 5, 1:45 am
From: Amit Mendapara <mendapara.a...@gmail.com>
Date: Wed, 4 Nov 2009 22:45:39 -0800 (PST)
Local: Thurs, Nov 5 2009 1:45 am
Subject: Re: MochiKit.DOM.getElementsByTagAndClassNam e performance
Look at my mochikit-ext project at https://launchpad.net/mochikit-ext.
I have implemented a jQuery style API in MochiKit.Query module (http://
bazaar.launchpad.net/~amit-mendapara/mochikit-ext/trunk/files) which
is based on Sizzle.js (http://github.com/jeresig/sizzle).

    MochiKit.DOM.getElementsByTagAndClassName("div", "some-class")

can be replaced with

    MochiKit.Query("div.some-class").get()

The Sizzle.js is the fastest selector engine out there. See
http://www.hvergi.net/arnar/public/sizzle/speed/# for the speed tests.

Regards
--
Amit Mendapara

On Nov 4, 9:22 pm, Bob Ippolito <b...@redivi.com> wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Fredrik  
View profile  
 More options Nov 5, 4:32 am
From: Fredrik <fblomqv...@gmail.com>
Date: Thu, 5 Nov 2009 01:32:21 -0800 (PST)
Local: Thurs, Nov 5 2009 4:32 am
Subject: Re: MochiKit.DOM.getElementsByTagAndClassNam e performance
I created a getElementsByClassName based on this code:
http://robertnyman.com/2008/05/27/the-ultimate-getelementsbyclassname...
http://code.google.com/p/getelementsbyclassname/

Pending a full selector integration something like this should be an
easy drop-in
solution to optimize getElementsByTagAndClassName.
(IE really needs some speedup here..)

// Fredrik Blomqvist

On Nov 5, 7:45 am, Amit Mendapara <mendapara.a...@gmail.com> wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alex Russell  
View profile  
 More options Nov 5, 4:42 pm
From: Alex Russell <a...@dojotoolkit.org>
Date: Thu, 5 Nov 2009 13:42:41 -0800
Local: Thurs, Nov 5 2009 4:42 pm
Subject: Re: [mochikit] Re: MochiKit.DOM.getElementsByTagAndClassNam e performance

On Nov 5, 2009, at 1:32 AM, Fredrik wrote:

Actually, it's not. The Acme engine in Dojo beats it by a fair bit on  
most real-world selectors. It's stand-alone and can be easily imported  
(like Sizzle).

Regards


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google