I know that using template.find()
or template.$
to search the DOM in Meteor is faster than searching all the DOM with document.querySelector()
or jQuery. But I don't know how much faster.
I imagine it would be directly related to the number of DOM nodes of the app but I don't know if that's the case or if there's any other optimization/degradation in Meteor that makes this assumption not so proportional.
Does anyone know about a performance test/result on this?
相关问题
- Faster loop: foreach vs some (performance of jsper
- Why wrapping a function into a lambda potentially
- Ado.net performance:What does SNIReadSync do?
- Device support warning : Google play 2019
- A good way to define default rendering templates i
相关文章
- DOM penalty of using html attributes
- Which is faster, pointer access or reference acces
- Django is sooo slow? errno 32 broken pipe? dcramer
- Understanding the difference between Collection.is
- parallelizing matrix multiplication through thread
- How to determine JS bottlenecks in React Native co
- Difference between SuspendLayout and BeginUpdate
- External dependencies (like bootstrap) in Meteor
template
is not equal todocument
. Adocument
can contain manytemplate
s.template.find
abstracts$
, buttemplate.find
doesn't add any functionality. Sotemplate.$
andtemplate.find
will more or less perform equally.$
is a common alias forjQuery
and when you pass a single string to thejQuery
function it'll go through a few more abstractions and probably land ondocument.querySelector
. That's whydocument.querySelector
is a lot faster thanjQuery
(jsperf is down right now, so I can't tell you how much faster).jQuery
is so much slower, that in most cases it'll probably a close call betweendocument.querySelector
andtemplate.$
.You'll get the best performance by getting a hold of a node wrapping your target and then using native-DOM functions. If you had a wrapping element inside your template, you could use the
template.firstNode
property. Otherwise you can just do what blaze does:template.firstNode.parentElement
. Then I'd usegetElementsByClassName
orgetElementById
. They are faster thenquerySelector
because withquerySelector
the query has to be parsed first. At least most of the time it depends on the number of nodes in your wrapping node and how far inside the tree the element your searching for is.I can't say that I've noticed any real performance increase for my users, but I will say that template.find() seems to give me a performance boost in how I code.
For example
Will not be manageable until I add an array slot like so:
Where as
Returns just that html element, meaning I don't have to treat it like an array every time.