-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Iterators 'blocking' each other #61
Comments
I'm not entirely sure about my assumptions here but this should generate a significant amount of CPU contention between iterators as we're still single-threaded (-ish, I know there's some magic happening in V8) and there's no I/O anywhere. On my machine, the time per item remains constant and the total time scales linearly with the overall number of items, regardless of the number of (quasi-)parallel chains. I get between 8.8 and 9.3 seconds for 10_000_000 items regardless of whether that's due to 1 chain going through 10_000_000 items or 5 chains going through 2_000_000 items each. Curiously, distributing 10_000_000 items across 100 chains going through 100_000 items each results in roughly 1.25x faster performance, finishing in ~ 6 seconds. I don't think it's something to do with the end event. |
Just ran some tests that seem to support what @jacoscaz is saying here Experiment import { ArrayIterator, range, AsyncIterator } from 'asynciterator'
for (let i = 0; i < 5; i++) {
const arr = range(0, 2000000); // I've tested with both `range` and `ArrayIterator`
const iterator = arr
.map((item) => item)
.map((item) => item)
.map((item) => item)
.map((item) => item)
.map((item) => item)
.map((item) => item)
.map((item) => item)
.map((item) => item)
.map((item) => item)
.map((item) => item);
console.time(`End event emitted for iterator ${i}`)
console.time(`First data event emitted for iterator ${i}`)
console.time(`Middle data event emitted for iterator ${i}`)
console.time(`Last data event emitted for iterator ${i}`)
iterator.on('data', (x) => {
if (x === 0) {
console.timeEnd(`First data event emitted for iterator ${i}`)
}
if (x === 1000000) {
console.timeEnd(`Middle data event emitted for iterator ${i}`)
}
if (x === 2000000 - 1) {
console.timeEnd(`Last data event emitted for iterator ${i}`)
}
}).on('end', () => {
console.timeEnd(`End event emitted for iterator ${i}`)
});
} Results
|
I suspect that this may be caused by #35 so don't worry for now.
This is a potential issue that I saw when perf testing the current PRs, but also saw in main.
If I run (on the main branch)
then the result is
(as opposed to ~3000ms for one)
I suspect the issue is that the
end
event is called asynchronously so has to wait for everything else to complete before we get back to it.The text was updated successfully, but these errors were encountered: