From 1dd4fcfe51e477f53191ab8bc5d80bf8d3843ca8 Mon Sep 17 00:00:00 2001 From: Tobias Laundal Date: Wed, 17 Aug 2022 14:18:28 +0200 Subject: [PATCH] feat: remove performance measurement --- .../performance/performanceMeasurements.ts | 43 ------------------- src/operators/reduceState.ts | 1 - src/reducer.ts | 22 +--------- 3 files changed, 2 insertions(+), 64 deletions(-) delete mode 100644 src/internal/performance/performanceMeasurements.ts diff --git a/src/internal/performance/performanceMeasurements.ts b/src/internal/performance/performanceMeasurements.ts deleted file mode 100644 index 146416be..00000000 --- a/src/internal/performance/performanceMeasurements.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { defaultErrorSubject } from '../defaultErrorSubject'; -import { Subject } from 'rxjs'; - -const PERFORMANCE_MARK_PREFIX = 'rxbeach'; - -const isWindowPerformanceDefined = () => - typeof window !== 'undefined' && window.performance; - -const getPerformanceMarker = (name: string) => { - return `${PERFORMANCE_MARK_PREFIX} - ${name}`; -}; - -const getStartMarker = (marker: string) => `${marker} - start`; -const getEndMarker = (marker: string) => `${marker} - end`; - -export const startPerformanceMeasurement = ( - name: string, - errorSubject: Subject = defaultErrorSubject -) => { - if (!isWindowPerformanceDefined()) return; - try { - const marker = getStartMarker(getPerformanceMarker(name)); - window.performance.mark(marker); - } catch (e) { - errorSubject.next(e); - } -}; - -export const endPerformanceMeasurement = ( - name: string, - errorSubject: Subject = defaultErrorSubject -) => { - if (!isWindowPerformanceDefined()) return; - const marker = getPerformanceMarker(name); - const startMarker = getStartMarker(marker); - const endMarker = getEndMarker(marker); - try { - window.performance.mark(endMarker); - window.performance.measure(marker, startMarker, endMarker); - } catch (e) { - errorSubject.next(e); - } -}; diff --git a/src/operators/reduceState.ts b/src/operators/reduceState.ts index eb5efbe5..bd789425 100644 --- a/src/operators/reduceState.ts +++ b/src/operators/reduceState.ts @@ -38,7 +38,6 @@ export const reduceState = ( pipe( combineReducers(defaultState, reducers, { errorSubject, - performanceMarker: name, }), startWith(defaultState), shareReplay({ diff --git a/src/reducer.ts b/src/reducer.ts index 04e8c91d..f85ff1bb 100644 --- a/src/reducer.ts +++ b/src/reducer.ts @@ -1,5 +1,5 @@ import { Observable, OperatorFunction, Subject, pipe } from 'rxjs'; -import { filter, map, merge, scan, tap } from 'rxjs/operators'; +import { filter, map, merge, scan } from 'rxjs/operators'; import { UnknownAction, UnknownActionCreator, @@ -8,10 +8,6 @@ import { } from './internal/types'; import { defaultErrorSubject } from './internal/defaultErrorSubject'; import { ofType } from './operators/operators'; -import { - endPerformanceMeasurement, - startPerformanceMeasurement, -} from './internal/performance/performanceMeasurements'; const wrapInArray = (val: T | T[]): T[] => Array.isArray(val) ? val : [val]; @@ -182,7 +178,6 @@ const ACTION_ORIGIN = Symbol('Action origin'); type CombineReducersConfig = { errorSubject?: Subject; - performanceMarker?: string; namespace?: string; }; @@ -207,9 +202,6 @@ type CombineReducersConfig = { * `defaultErrorSubject`, which will rethrow the errors globally, as uncaught * exceptions. The stream will not complete or emit any value upon an error. * - * If a performanceMarker is passed, combineReducers will add performance marks - * using the window.performance API - * * @param seed The initial input to the first reducer call * @param reducers The reducer entries that should be combined * @param namespace Namespace to pass on to the reducers. Note that this will @@ -219,11 +211,7 @@ type CombineReducersConfig = { export const combineReducers = ( seed: State, reducers: RegisteredReducer[], - { - errorSubject = defaultErrorSubject, - performanceMarker, - namespace, - }: CombineReducersConfig = {} + { errorSubject = defaultErrorSubject, namespace }: CombineReducersConfig = {} ): OperatorFunction => { const actionReducers = reducers.filter(isActionReducer); const streamReducers = reducers.filter(isStreamReducer); @@ -250,9 +238,6 @@ export const combineReducers = ( ofType(...actionReducers.flatMap((reducerFn) => reducerFn.trigger.actions)), map((action): Packet => ({ origin: ACTION_ORIGIN, value: action })), merge(...source$s), - tap(() => { - if (performanceMarker) startPerformanceMeasurement(performanceMarker); - }), scan( ({ state }, packet) => { try { @@ -279,9 +264,6 @@ export const combineReducers = ( }, { state: seed, caughtError: false } ), - tap(() => { - if (performanceMarker) endPerformanceMeasurement(performanceMarker); - }), filter(({ caughtError }) => caughtError === false), map(({ state }) => state) );