Skip to content

Commit

Permalink
perf(mergeMapTo): remove tryCatch/errorObject (~2x improvement)
Browse files Browse the repository at this point in the history
Before:
                                      |     RxJS 4.0.7 | RxJS 5.0.0-beta.1 | factor | % improved
-------------------------------------------------------------------------------------------------
mergemapto-resultselector - immediate |   811 (±1.50%) |    5,376 (±1.10%) |  6.63x |     562.7%
        mergemapto-scalar - immediate | 6,110 (±0.45%) |  113,487 (±0.91%) | 18.58x |   1,757.5%
               mergemapto - immediate | 1,439 (±0.95%) |   17,017 (±0.29%) | 11.83x |   1,082.8%
            mergemapto-resultselector |   369 (±0.43%) |    1,957 (±0.45%) |  5.30x |     429.7%
                    mergemapto-scalar | 3,740 (±0.45%) |   66,278 (±1.18%) | 17.72x |   1,672.3%
                           mergemapto |   490 (±0.39%) |    3,685 (±0.44%) |  7.52x |     651.7%

After:
                                      |     RxJS 4.0.7 | RxJS 5.0.0-beta.1 | factor | % improved
-------------------------------------------------------------------------------------------------
mergemapto-resultselector - immediate |   810 (±1.70%) |   11,428 (±3.41%) | 14.11x |   1,310.6%
        mergemapto-scalar - immediate | 6,401 (±2.48%) |  117,259 (±2.09%) | 18.32x |   1,731.9%
               mergemapto - immediate | 1,452 (±0.44%) |   17,406 (±0.35%) | 11.99x |   1,098.9%
            mergemapto-resultselector |   383 (±1.24%) |    3,288 (±0.42%) |  8.58x |     757.7%
                    mergemapto-scalar | 3,837 (±0.57%) |   62,294 (±3.05%) | 16.23x |   1,523.3%
                           mergemapto |   525 (±2.37%) |    3,795 (±0.79%) |  7.23x |     622.6%
  • Loading branch information
luisgabriel authored and kwonoj committed Feb 6, 2016
1 parent 8e5508d commit 42bcced
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/operator/mergeMapTo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import {Observable} from '../Observable';
import {Operator} from '../Operator';
import {PartialObserver} from '../Observer';
import {Subscriber} from '../Subscriber';
import {tryCatch} from '../util/tryCatch';
import {errorObject} from '../util/errorObject';
import {Subscription} from '../Subscription';
import {OuterSubscriber} from '../OuterSubscriber';
import {InnerSubscriber} from '../InnerSubscriber';
Expand Down Expand Up @@ -73,17 +71,26 @@ export class MergeMapToSubscriber<T, R, R2> extends OuterSubscriber<T, R> {
innerSub: InnerSubscriber<T, R>): void {
const { resultSelector, destination } = this;
if (resultSelector) {
const result = tryCatch(resultSelector)(outerValue, innerValue, outerIndex, innerIndex);
if (result === errorObject) {
destination.error(errorObject.e);
} else {
destination.next(result);
}
this.trySelectResult(outerValue, innerValue, outerIndex, innerIndex);
} else {
destination.next(innerValue);
}
}

private trySelectResult(outerValue: T, innerValue: R,
outerIndex: number, innerIndex: number): void {
const { resultSelector, destination } = this;
let result: R2;
try {
result = resultSelector(outerValue, innerValue, outerIndex, innerIndex);
} catch (err) {
destination.error(err);
return;
}

destination.next(result);
}

notifyError(err: any): void {
this.destination.error(err);
}
Expand Down

0 comments on commit 42bcced

Please sign in to comment.