Skip to content

optimize-selectors qSA before Sizzle #694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 26, 2023
Merged

Conversation

mr21
Copy link
Contributor

@mr21 mr21 commented Dec 31, 2015

Hi :)

Here a first draft (who probably contain few mistakes) for the issue #666.

@agcolom
Copy link
Member

agcolom commented Jan 21, 2016

@dmethvin @timmywil It would be truly wonderful if you could review this PR. Thank you :-)


Beginning your selector with an ID is always best.
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this example might need a small introduction. Even 1-2 sentences should do it.

@AurelioDeRosa
Copy link
Member

Hi @mr21. Are you still interested in this PR?

@mr21
Copy link
Contributor Author

mr21 commented Mar 14, 2016

... I'm really sorry, yes I'm still interested.
I'll push ASAP your change

@kswedberg
Copy link
Member

@mr21 Make sure you rebase from here before continuing your work. I merged a PR based on another issue and removed/rearranged a bunch of stuff, so you might have conflicts.

@mr21
Copy link
Contributor Author

mr21 commented Mar 14, 2016

Understood :)

@mr21 mr21 force-pushed the optimize-selectors branch from 78fd9d4 to cb2c81b Compare March 16, 2016 18:31
@mr21
Copy link
Contributor Author

mr21 commented Mar 16, 2016

Hi :)

So, I have rebased and repush again my commit with the @AurelioDeRosa's modifications.
Except that I didn't add yet a small introduction in place of this removed sentence:
Beginning your selector with an ID is a safe bet.

@AurelioDeRosa
Copy link
Member

Hi @mr21.

With "yet" you mean that you'll add another commit to update the PR?

@mr21
Copy link
Contributor Author

mr21 commented Mar 17, 2016

Hi :)

For the moment I have replaced this:


ID-Based Selectors

Beginning your selector with an ID is a safe bet.

// Fast:
$( "#container div.robotarm" );

// Super-fast:
$( "#container" ).find( "div.robotarm" );

With the first approach, jQuery queries the DOM using document.querySelectorAll(). With the second, jQuery uses document.getElementById(), which is faster, although the speed improvement may be diminished by the subsequent call to .find().


by this:

Save calls to querySelectorAll

querySelectorAll is already really fast, if you want maintain this speed try to call it the least possible.

// If in your HTML there are 2 .container with 5 div in each,
// this line will call querySelectorAll 13 times (1 + 2 + 2*5).
$( ".container" ).children( "div" ).find( ".robotarm" );

// Against only 1 call with this:
$( ".container div .robotarm" );

But I don't know what I have to write to introduce my example.
If you have an idea, I will commit it quickly.

Thanks for your patience :)

Base automatically changed from master to main March 8, 2021 17:15
@Krinkle Krinkle closed this Mar 26, 2023
@Krinkle Krinkle reopened this Mar 26, 2023
@Krinkle
Copy link
Member

Krinkle commented Mar 26, 2023

I've confirmed from the previous CLA data that this PR was indeed signed as the bot originally indicated:

cb2c81b

/var/www/jquery-license/output/jquery/learn.jquery.com/cb/cb2c81b5816f112368c34090f4214bf613c1b881.json
{
  "data":{
    "commits":[{
      "hash":"cb2c81b5816f112368c34090f4214bf613c1b881",
      "email":"thomastortorini@gmail.com",
      "name":"Thomas Tortorini"
    }],
    "neglectedCommits":[],
    "neglectedAuthors":[]
  },
  "state":"success",
  "description":"All authors have signed the CLA"
}

@Krinkle Krinkle merged commit 910cc5f into jquery:main Mar 26, 2023
@jquery jquery deleted a comment from linux-foundation-easycla bot Mar 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

7 participants