Skip to content

Performance: Reduce synchronization #107

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

Merged
merged 3 commits into from
Jan 22, 2013

Conversation

benjchristensen
Copy link
Member

Performance changes as part of #104 and is an extension of work done in pull #106.

This code was used to test the performance:

    public void runCompositionTest(Integer[] values) {
        System.out.println("runCompositionTest");

        final AtomicInteger onNextSum = new AtomicInteger(0);
        final long start = System.nanoTime();

        MathFunction m = new MathFunction();
        // 50 levels of composition (same function so that's not the cost)
        Observable.from(values)
                .map(m).map(m).map(m).map(m).map(m).map(m).map(m).map(m).map(m).map(m)
                .map(m).map(m).map(m).map(m).map(m).map(m).map(m).map(m).map(m).map(m)
                .map(m).map(m).map(m).map(m).map(m).map(m).map(m).map(m).map(m).map(m)
                .map(m).map(m).map(m).map(m).map(m).map(m).map(m).map(m).map(m).map(m)
                .map(m).map(m).map(m).map(m).map(m).map(m).map(m).map(m).map(m).map(m)
                .subscribe(new TestObserver(onNextSum, start));
    }

Before it took:

Sum: 710082754 Time: 60.605ms

By reducing the nested synchronization (eliminating most of it) it is now running at:

Sum: 710082754 Time: 22.429ms

- Convert operators to implement Func1 instead of extend Observable
- Change Observable to concete instead of abstract
- subscribe is now controlled by the concrete class so we can control the wrapping of a Func to be executed when subscribe is called
- removed most wrapping inside operators with AtomicObservable except for complex operators like Zip that appear to still need it

While doing these changes the util/function packages got moved a little as well to make more sense for where the Atomic* classes should go
- migrated Func1 to OperatorSubscribeFunction for internal operator implementations
- do not wrap with AtomicObserver when it's a trusted operator

ReactiveX#104
benjchristensen added a commit that referenced this pull request Jan 22, 2013
Performance: Reduce synchronization
@benjchristensen benjchristensen merged commit fa1af64 into ReactiveX:master Jan 22, 2013
rickbw pushed a commit to rickbw/RxJava that referenced this pull request Jan 9, 2014
jihoonson pushed a commit to jihoonson/RxJava that referenced this pull request Mar 6, 2020
JavaDoc correction for ConcurrentEvictingQueue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant