-
Notifications
You must be signed in to change notification settings - Fork 480
"Clever Conditionals" in Performance is wrong #258
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
Comments
@ithcy Can you make a pull request that updates the content with correct information? Include:
|
@rwldrn I could, but honestly I'm not sure this page should even exist... It looks like it was pulled wholesale onto learn.jquery.com along with the rest of the Performance Best Practices section of jQuery Fundamentals, who in turn got it from Paul Irish's 2009 "jQuery Anti-Patterns for Performance" presentation (http://paulirish.com/2009/perf/ , 48:20 in the video or slide 61). It just gets a brief mention in the presentation, and only in the specific context of saving a few bytes when you're forced to include some JS in the document head rather than at the end of the body. The 2 latter examples are there because they take up proportionally fewer bytes as the number of comparisons grows. So they're better for page-loading performance, worse for overall computational performance, but people are going to assume that example 2 and 3 are just "best practice because jquery.com says so" and use them all over without understanding what they're doing. In other words if this was a question on stackoverflow I'd vote to close it as "too localized" :) I'm not sure it belongs at all in the performance section of a site that's sure to be the first stop for thousands of new jQuery students, especially when it's just sort of blobbed in there without the lengthy discussion that's needed to establish the correct context for this very specific bit of advice. Do you think the page should be amended to add the context. or just removed? |
I think we should just remove it for now |
@ajpiano You need to remove the reference from order.yml as well. |
I just did |
GMTA :) Thanks for noticing this @ithcy |
NP! :) |
@ithcy +1 (even though it already happened) I wanted to encourage you to contribute to the overall improvement of the content.. which you did, but by other means :D Thanks!! |
…tion is too context specific and not a generally applicable best practice. Fixes jquery#258.
http://learn.jquery.com/performance/clever-conditionals/
jsperf: http://jsperf.com/jquery-clever-conditionals
The "better" way (using a regex) is 94% slower than the "old way" (simple equality comparison), and I would argue that it's also much less obviously understandable when skimming over code.
The object literal lookup method is also 78% slower than the "old way", but it's not implied that it's "better". I'm not sure what the point is of this example as it's almost as slow and hard to read as the "better" way.
Also, the "old way" should probably use the triple-equals for comparison.
The text was updated successfully, but these errors were encountered: