Giter VIP home page Giter VIP logo

Comments (3)

zenparsing avatar zenparsing commented on May 26, 2024

Background question: have we documented a use case (besides performance considerations) for synchronous subscribe? What use cases would feel pain if subscribe was always queued?

from es-observable.

jhusain avatar jhusain commented on May 26, 2024

I think it's fair to say the only reason to allow synchronous subscription is performance. I know @sebmarkbage is relying on sync subscription to deliver cached data quickly. Definitely open to reconsidering this, but we should bear in mind that scheduling on subscribe does not imply one schedule. If data is cached at the source (HTTP caching for example) and you have a series of combinators (flatMap) over the cached observable, then scheduling on subscription can easily degrade into scheduling on notification. In flatMap each item will create an Observable and therefore schedule. If all the data being retrieved is cached, this number of unnecessary schedules can easily multiply. Netflix has this case today: we cache at the source and subscribe to combinator chains over the cached data. This is one of the main rationales for treating Observanle differently than Promises - the cost of schedules for scalar values is per operation. The cost of schedules in vectors sources can Scale to the size of the vector.

from es-observable.

zenparsing avatar zenparsing commented on May 26, 2024

Ah, right. Once you allow allow for nested observables the cost of subscription is no longer constant: when flattening a two dimensional stream the cost will be linear with the length of the outer stream.

After thinking about this for a while, I feel like it's pretty dodgy to force subscription onto the microtask queue at all. Even with promises, we don't force asynchrony on the initializer:

console.log("1");
new Promise(resolve => {
    console.log("2");
    resolve(null);
});
console.log("3");
// Logs 1, 2, 3

Forcing subscription onto the MT queue is equivalent in my mind to forcing the promise initializer onto the MT queue. The only thing that matters is delivery, and if we are committed to synchronous delivery, I see no real advantage in having a public method which forces asynchronous subscription.

My intuition says that it would be better to forego this compromise, or at least hold out on it for a while.

from es-observable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.