sizzle
sizzle copied to clipboard
Avoid reading outside of collection bounds
Consider the following collection:
const array = ['a', 'b', 'c'];
Retrieving array[0] can be done relatively quickly. However, when the property doesn’t exist on the receiver, JavaScript engines must continue to look up the prototype chain until either the property is found or the chain ends. This is inherently slower than not doing any prototype chain lookups. Retrieving an out-of-bounds index, e.g. array[3], triggers this scenario, resulting in decreased performance.
This patch changes the way some loops are written to avoid running into the slow case unnecessarily.
Similar patch for jQuery: https://github.com/jquery/jquery/pull/3769
Hey.
This looks nice to me. How this reflects on the byte size though? Maybe you could provide a small jsperf as well?
This is pretty big... can you put together a jsPerf or other benchmark (example, and yes I'm aware of the irony) showing the value?
raw gz Sizes
65502 19586 dist/sizzle.js
19851 7421 dist/sizzle.min.js
raw gz Compared to master @ 840b647cd1ddd9d9aec3cde73af3f697fbf068d7
+194 +51 dist/sizzle.js
+82 +54 dist/sizzle.min.js
If the Chrome perf quirk was the main driver for this, that has been fixed.
- :x: - Mathias Bynens The commit (893e3c5c8873dff6bc84f149d0c42bf14533afac ,d85f4fbb5c04b180b892595826a2159f36f6c5fa) is not authorized under a signed CLA. Please click here to be authorized. For further assistance with EasyCLA, please submit a support request ticket.