Open DanielRosenwasser opened 2 weeks ago
for-of
loops create iterators butfor (let i = 0; i < arr.length; i++)
doesn't.
I'd have expected for (const foo of foos) {}
to be highly optimized by engines at this point. Since the iterator for arrays doesn't actually do anything, I'd be surprised if most engines didn't optimize it away in this case.
I'd have expected
for (const foo of foos) {}
to be highly optimized by engines at this point. Since the iterator for arrays doesn't actually do anything, I'd be surprised if most engines didn't optimize it away in this case.
Still not really, a for-of-loop is still often many times slower than a for-loop, e.g. this has a difference of 10x in v8 , and 4x in jsc (curiously inlining the forOfLoop function makes v8 have a 4x difference as well):
const arr = Array.from({ length: 10_000_000 }, () => Math.random());
function forLoop() {
let sum = 0;
for (let i = 0; i < arr.length; i += 1) {
sum += arr[i];
}
}
function forOfLoop() {
let sum = 0;
for (const v of arr) {
sum += v;
}
}
console.time("for-loop");
for (let i = 0; i < 100; i += 1) {
forLoop();
}
console.timeEnd("for-loop");
console.time("for-of-loop");
for (let i = 0; i < 100; i += 1) {
forOfLoop();
}
console.timeEnd("for-of-loop");
Coverage Reporting
https://github.com/microsoft/TypeScript/pull/58850
npm tests -- --no-lint --coverage
.Knip
https://github.com/microsoft/TypeScript/pull/56817
/** @knipignore */
tag to the preceding comment.@internal
Tagging--stripInternal
is supposed to do, and say it only applies to JSDoc comments.// Do not add an @internal tag to the next declaration
, since TypeScript will now consider that unrelated.--stripInternal
, we've always said "it has bugs, ehhh, arguable behavior."More "Primitive" Operations in Core Utilities
https://github.com/microsoft/TypeScript/pull/58873
some
function was just a big hot path.||
checks for truthiness, but??
only checks fornull
/undefined
.undefined
are faster than truthiness.for
-of
loops create iterators butfor (let i = 0; i < arr.length; i++)
doesn't.core.ts
to avoid too much noise.