Skip to content

Commit 9d6088b

Browse files
author
François Andrieux
committed
fixed error prettier
1 parent 288652c commit 9d6088b

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

dash/dash-renderer/src/actions/dependencies_ts.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,27 @@ export const getReadyCallbacks = (
233233
}
234234
}
235235

236+
// Ramda.JS `difference` function is slow because it compares objects entirely
237+
// This cause the following `filter` to be exponentially slow as the number of inputs or outputs grow
238+
// We can optimize this by comparing only the `id+prop` part of the inputs & outputs.
239+
// Original difference takes 380ms on average to compute difference between 200 inputs and 1 output.
240+
// The following function takes 1-2ms on average.
241+
const differenceBasedOnId = (inputs: any[], outputs: any[]): any[] =>
242+
inputs.filter(
243+
input =>
244+
!outputs.some(
245+
output =>
246+
combineIdAndProp(input) === combineIdAndProp(output)
247+
)
248+
);
249+
236250
// Find `requested` callbacks that do not depend on a outstanding output (as either input or state)
237251
// Outputs which overlap an input do not count as an outstanding output
238252
return filter(
239253
cb =>
240254
all<ILayoutCallbackProperty>(
241255
cbp => !outputsMap[combineIdAndProp(cbp)],
242-
difference(
256+
differenceBasedOnId(
243257
flatten(cb.getInputs(paths)),
244258
flatten(cb.getOutputs(paths))
245259
)

dash/dash-renderer/src/observers/prioritizedCallbacks.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {find, flatten, map, partition, pluck, sort, uniq} from 'ramda';
1+
import {find, flatten, map, partition, sort} from 'ramda';
22

33
import {IStoreState} from '../store';
44

@@ -53,13 +53,16 @@ const getStash = (
5353
return {allOutputs, allPropIds};
5454
};
5555

56-
const getIds = (cb: ICallback, paths: any) =>
57-
uniq(
58-
pluck('id', [
59-
...flatten(cb.getInputs(paths)),
60-
...flatten(cb.getState(paths))
61-
])
62-
);
56+
const getIds = (cb: ICallback, paths: any) => {
57+
const items = [
58+
...flatten(cb.getInputs(paths)),
59+
...flatten(cb.getState(paths))
60+
];
61+
62+
const uniqueIds = new Map(items.map(item => [stringifyId(item.id), item]));
63+
const uniqueItems = Array.from(uniqueIds.values());
64+
return uniqueItems;
65+
};
6366

6467
const observer: IStoreObserverDefinition<IStoreState> = {
6568
observer: async ({dispatch, getState}) => {

0 commit comments

Comments
 (0)