ReactiveX / IxJS

The Interactive Extensions for JavaScript
https://reactivex.io/IxJS/
MIT License
1.33k stars 74 forks source link

Weird memory behaviour with merge #322

Closed nordfjord closed 3 years ago

nordfjord commented 3 years ago

I've been running into very strange memory behaviour with merged async iterables.

Some investigation leads me to believe Promise.race is the culprit.

I used this test-case locally:

// every 10 minutes
const slowMovingIterable = interval(600000);
const fastMovingIterable = interval(10).pipe(
  // we map it to something big
  map(() => Array.from({ length: 3000 }).map(() => Math.random())),
);

merge(slowMovingIterable, fastMovingIterable).forEach(() => {});

Then I looked at the memory tools in chrome and found that memory was steadily increasing. It seems that promise references are kept around in memory until both promises have emitted when using Promise.race

If I change the interval of the slow moving observable to 10 then memory usage is stable.

nordfjord commented 3 years ago

Closing as this was solved with #323 and released in ix@4.3.1