Comments (5)
Here's some performance data I've gathered, based on the script located under "perf/subscription.js", executed on my rather old 2009 macbook:
[Microtask subscription]
Subscriptions: 100000
Sequence Size: 10
Deliveries: 1000000
Time: 8423ms
[Synchronous subscription]
Subscriptions: 100000
Sequence Size: 10
Deliveries: 1000000
Time: 2774ms
Delta: 5649ms
Delta/subscription: 0.05649ms
Delta/delivery: 0.005649ms
Obviously it's slower to go through the microtask queue than to perform a direct function call, but it's hard for me to tell what to make of this.
Since we pay the queuing cost only once per sequence, the averaged cost per delivery is inversely proportional to the size of the sequence. Whether we view the cost as significant or not seems to depend on what we choose to be a typical sequence size.
@jhusain what do you think?
from proposal-observable.
Here we pay the queuing cost only once per subscription because there is one observable. All it takes is one flatMap on this observable that retrieves data from a data store with a cache, and now we have a schedule per notification.
from proposal-observable.
That's a common misconception, but not true. Once you're in the microtask queue, you've already paid the cost, and it won't be paid again. In other words the microtask queue is implemented as
while (queue.length > 0) {
task = queue.pop();
task();
}
If task
throws an exception, you might pay a hit, as you have to back out and go back through the queue again. But the cost for a single microtask subscription is the same as for multiple---namely, it's the cost of letting the rest of the synchronous code that's planning to run this turn, run.
from proposal-observable.
The cost I'm referring to here is the cost of unwinding the stack and winding it up again vs. just building up the stack. If the overhead here is indeed small, I'm open to asynchrony all the time. The acid test would be whether the scheduling was visible to the naked eye in a mouse drag or other gesture for example. If the scheduling introduces any latency it would be a serious problem as event composition is one of the key scenarios. Should be easy to test.
from proposal-observable.
We can't really do asynchronous delivery (i.e. per-iteration) because the data flow is two-way. Data for the iteration flows from the observable to the observer, and a completion value flows back down to the observable. That may be a thrown exception ("throw") or it may be { done: true}
("return"), or it may just carry some value (a backpressure signal, for instance). But we need to maintain the current stack in order to receive that data from the observer.
from proposal-observable.
Related Issues (20)
- Invalid test based on Interface. HOT 1
- `obs.subscribe(next, error, complete)` should bind their callbacks to `undefined` when present HOT 5
- Why does `Observable.prototype.subscribe` report thrown errors from `observer.start(sub)` asynchronously instead of just propagating them?
- Minor spec bug WRT cleanup in `subscribe`
- `Observable.from` iteration functions incorrectly assume their observer parameter is native HOT 1
- [ALTERNATIVE] Proposal for an alternative
- Cleanup function should be passed to the SubscriptionObserver
- Simplification of Observable API HOT 69
- End a subscription if a completion token is returned HOT 1
- Even simpler API HOT 4
- Reduced API with async/await support HOT 23
- Observable should be async HOT 5
- Syntax Support HOT 4
- Alternative: Pub/Sub
- Moving to an API with AbortSignal HOT 9
- Retain core API and leave operators to user-land libraries HOT 15
- Permit unsubscribe to return a promise HOT 3
- Is there any update? HOT 34
- Support [Symbol.dispose]() for unsubscribe() HOT 1
- Unsubscribe
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from proposal-observable.