Giter VIP home page Giter VIP logo

Comments (7)

steveorsomethin avatar steveorsomethin commented on May 12, 2024

Commenting here at the request of @Blesh.

I can't think of any concrete macro tests, but based on my measurements, perf challenges go in order of: subscribe() cost, currentThreadScheduler on synchronous producers, stack depth. In traces I've also seen a ton of AutoDetachObserver spam, but haven't been able to isolate and measure its impact since it seems cross-cutting.

With respect to subscribe, generally both on the server and client we deal with very small Observables, typically in the range of 1-10 items. That isn't to say that some other consumer won't have a firehose observable, so we should still make sure observer chains remain shallow or even collapsed via deforesting, and schedulers remain lean or even optional. However, in terms of real cases I can only speak to the significant cost of short-lived observables.

When playing with most.js, I found that while most was indeed tens of times faster than Rx for synchronous sources and operators, the following was enough to cause them to converge:

range(0, 1000).flatMap(returnValue).flatMap(returnValue).flatMap(returnValue)

Most's official flatMap tests showed a significant win because they weren't really testing flatMap/subscribe; it was a flatMap of large ranges into large ranges, which ended up being more of a benchmark of onNext, especially since synchronous sources didn't go through a scheduler at all (I don't know if that has since changed).

If we make flatMap over very small observables fast, I think the most common UI/service aggregation cases are covered. The trampolining in currentThreadScheduler is a serious perf hit though, so it's worth trying to bypass/optimize it. However, the majority of real code I've seen doesn't leverage synchronous sources nearly as often as it leverages flatMap-like operators over potentially-async sources.

I'll see if I can find some time to contribute some tests based on these observations.

from rxjs.

ktrott avatar ktrott commented on May 12, 2024

From RxJS meeting
Attendees: @Blesh, @trxcllnt, @steveorsomethin, @ktrott

Focus on Macro tests for places where we are creating new observables and subscribing to internal observables: zip and async ones
Macro performance will capture memory footprints: creating objects, garbage collection, etc.

TODO: Identify the list of operators that we want to focus on.

from rxjs.

benlesh avatar benlesh commented on May 12, 2024

Really any operator that creates objects internally such as subscriptions or observables... so for example, groupBy creates Observables internally. flatMap creates subscriptions internally. concat creates subscriptions internally.

Likewise, operators that cause any buffering, like buffer, window, subscribeOn, observeOn, etc. Should probably have accompanying macro perf tests:

  • flatMap
  • merge
  • mergeAll
  • concat
  • concatAll
  • subscribeOn
  • observeOn
  • groupBy
  • groupByUntil

from rxjs.

benlesh avatar benlesh commented on May 12, 2024

I'm unsure if Subjects should have macro perf tests. But I think multicast might be a good idea.

Thoughts? @steveorsomethin?

from rxjs.

steveorsomethin avatar steveorsomethin commented on May 12, 2024

@Blesh It's probably wise, though designing the test is interesting. The overhead of Subject.subscribe seems minimal since it's just pushing into an observer array. Instead, I'd expect the macro bottleneck to be cases where subjects are treated as observers since Subject.onNext needs to copy its observers array every time it is invoked. Even then, that seems to only be a serious problem with large numbers of observers and firehose source observables.

from rxjs.

robwormald avatar robwormald commented on May 12, 2024

couple of prior arts that include Rx, might be good to see the improvement
https://github.com/spion/async-compare/ (bit out of date)
https://github.com/petkaantonov/bluebird/tree/master/benchmark (newer fork of above)
from http://spion.github.io/posts/why-i-am-switching-to-promises.html

from rxjs.

benlesh avatar benlesh commented on May 12, 2024

I think we've identified what we want to test for macro perf and outlined them in #100. Choosing this issue for now.

from rxjs.

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.