mirror of
https://github.com/gradio-app/gradio.git
synced 2025-04-06 12:30:29 +08:00
Optimize frontend's is_dep calls (#4334)
* Optimize is_dep (36 to 12 msec) * Call is_dep less (12 msec to 9 msec) * Changelog --------- Co-authored-by: pngwn <hello@pngwn.io>
This commit is contained in:
parent
caceb7a5b1
commit
59e487d30c
@ -10,7 +10,7 @@ No changes to highlight.
|
||||
|
||||
## Other Changes:
|
||||
|
||||
No changes to highlight.
|
||||
- Performance optimization in the frontend's Blocks code by [@akx](https://github.com/akx) in [PR 4334](https://github.com/gradio-app/gradio/pull/4334)
|
||||
|
||||
## Breaking Changes:
|
||||
|
||||
|
@ -94,38 +94,26 @@
|
||||
type: "inputs" | "outputs",
|
||||
deps: Array<Dependency>
|
||||
) {
|
||||
let dep_index = 0;
|
||||
for (;;) {
|
||||
const dep = deps[dep_index];
|
||||
if (dep === undefined) break;
|
||||
|
||||
let dep_item_index = 0;
|
||||
for (;;) {
|
||||
const dep_item = dep[type][dep_item_index];
|
||||
if (dep_item === undefined) break;
|
||||
for (const dep of deps) {
|
||||
for (const dep_item of dep[type]) {
|
||||
if (dep_item === id) return true;
|
||||
dep_item_index++;
|
||||
}
|
||||
|
||||
dep_index++;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const dynamic_ids: Set<number> = components.reduce<Set<number>>(
|
||||
(acc, { id, props }) => {
|
||||
const is_input = is_dep(id, "inputs", dependencies);
|
||||
const is_output = is_dep(id, "outputs", dependencies);
|
||||
|
||||
if (!is_input && !is_output && has_no_default_value(props?.value))
|
||||
acc.add(id); // default dynamic
|
||||
if (is_input) acc.add(id);
|
||||
|
||||
return acc;
|
||||
},
|
||||
new Set()
|
||||
);
|
||||
const dynamic_ids: Set<number> = new Set();
|
||||
for (const comp of components) {
|
||||
const { id, props } = comp;
|
||||
const is_input = is_dep(id, "inputs", dependencies);
|
||||
if (
|
||||
is_input ||
|
||||
(!is_dep(id, "outputs", dependencies) &&
|
||||
has_no_default_value(props?.value))
|
||||
) {
|
||||
dynamic_ids.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
function has_no_default_value(value: any) {
|
||||
return (
|
||||
|
Loading…
x
Reference in New Issue
Block a user