Get the latest tech news
Complex Iterators Are Slow
Thursday, 31 July 2025 Timi, my pure JavaScript B-Tree, achieves best in class iteration speed in part because I replaced Iterators with callbacks. They might be convenient, but the design of JavaScript Iterators is inherently slow for complex iteration as it prevents your compiler from inlining code.
When performance tuning, you can use the --trace-turbo-inlining flag to ask TurboFan (one of V8's optimising compilers) to report when it inlines a function. Iteration in Timi, for example, can involve complicated walks up and down the tree and the code is - necessarily - too complex to be inlined. If I remove the padding code, the Iterator's next() method can be inlined and the performance gap narrows significantly:
Or read this on Hacker News