![]() Fast paths are fast because they get to make restrictive assumptions. (2) Speed is fundamentally at odds with flexibility. Since none of those resources are infinite, we'll always have to choose where to spend them, and where not. (1) Implementing fast paths comes at a cost: it takes more engineering time to develop (and debug) them it takes more time to update them when the JS spec changes it creates an amount of code complexity that quickly becomes unmanageable leading to further development slowdown and/or functionality bugs and/or security bugs it takes more binary size to ship them to our users and more memory to load such binaries it takes more CPU time to decide which path to take before any of the actual work can start etc. As much as we'd love to just make everything fast, there are two reasons why that won't happen: More generally: you'll probably see the same general pattern for many other JS builtins - it's a natural consequence of running on an optimizing engine for a dynamic language. slice()'s "HasElement" check on every iteration. Let name = cls = Array ? "Array" : "ArraySub" Ĭonsole.log(`-\nRunning with $ loop would be about twice as fast, even if you add an if (i in source) check to reflect. Why would that be?Īnd, here's the code: // empty subclass for testing purposes slice() copy is 26x slower on the sub-class and more than 2x slower than the manual copy. The manual copy is about the same both ways. Here are the numbers: Running with Array(100,000,000) I then ran those two tests for both an Array and my own empty subclass ArraySub. slice() and I made a copy manually by then iterating over the array and assigning values to a new array. Anyone have any ideas? Is this a bug or is there some aspect to this that would/could explain it?įor the test, I created a 100,000,000 unit array filled with increasing numbers. slice() can be more than 2x slower than just manually copying elements from one array to another. While, I could imagine that there might be some compiler optimizations around a non-subclassed array, what I do not understand at all is how. In node v14.3.0, I discovered (while doing some coding work with very large arrays) that sub-classing an array can cause.
0 Comments
Leave a Reply. |