chore: reduce re-render times for params in playground
This commit is contained in:
@@ -359,18 +359,18 @@ export default (props: any) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// 先清除旧的性能标记
|
// clear previous marks and measures
|
||||||
performance.clearMarks();
|
performance.clearMarks();
|
||||||
performance.clearMeasures();
|
performance.clearMeasures();
|
||||||
|
|
||||||
// 记录开始时间
|
// record start time
|
||||||
performance.mark('route-start');
|
performance.mark('route-start');
|
||||||
|
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
// 记录结束时间
|
// record end time
|
||||||
performance.mark('route-end');
|
performance.mark('route-end');
|
||||||
|
|
||||||
// 确保 `route-start` 存在后再测量
|
// make sure `route-start` exists
|
||||||
if (performance.getEntriesByName('route-start').length > 0) {
|
if (performance.getEntriesByName('route-start').length > 0) {
|
||||||
performance.measure('route-change', 'route-start', 'route-end');
|
performance.measure('route-change', 'route-start', 'route-end');
|
||||||
|
|
||||||
@@ -379,7 +379,7 @@ export default (props: any) => {
|
|||||||
`[Performance] Route change to ${location.pathname} took ${measure.duration.toFixed(2)}ms`
|
`[Performance] Route change to ${location.pathname} took ${measure.duration.toFixed(2)}ms`
|
||||||
);
|
);
|
||||||
|
|
||||||
// 清理标记
|
// clear marks and measures
|
||||||
performance.clearMarks();
|
performance.clearMarks();
|
||||||
performance.clearMeasures();
|
performance.clearMeasures();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -588,6 +588,10 @@ const options = [
|
|||||||
{
|
{
|
||||||
label: '--jinja',
|
label: '--jinja',
|
||||||
value: '--jinja'
|
value: '--jinja'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '--context-shift',
|
||||||
|
value: '--context-shift'
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ type ParamsSettingsProps = {
|
|||||||
paramsConfig?: ParamsSchema[];
|
paramsConfig?: ParamsSchema[];
|
||||||
initialValues?: Record<string, any>; // for initial values when switch model, aviod update values from setParams
|
initialValues?: Record<string, any>; // for initial values when switch model, aviod update values from setParams
|
||||||
extra?: React.ReactNode;
|
extra?: React.ReactNode;
|
||||||
watchFields?: any[];
|
watchFields?: string[];
|
||||||
|
formFields?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const ParamsSettings: React.FC<ParamsSettingsProps> = forwardRef(
|
const ParamsSettings: React.FC<ParamsSettingsProps> = forwardRef(
|
||||||
@@ -36,7 +37,8 @@ const ParamsSettings: React.FC<ParamsSettingsProps> = forwardRef(
|
|||||||
initialValues,
|
initialValues,
|
||||||
paramsConfig,
|
paramsConfig,
|
||||||
modelList,
|
modelList,
|
||||||
watchFields = [],
|
watchFields,
|
||||||
|
formFields,
|
||||||
showModelSelector = true,
|
showModelSelector = true,
|
||||||
extra
|
extra
|
||||||
},
|
},
|
||||||
@@ -86,7 +88,7 @@ const ParamsSettings: React.FC<ParamsSettingsProps> = forwardRef(
|
|||||||
);
|
);
|
||||||
|
|
||||||
const renderFields = useMemo(() => {
|
const renderFields = useMemo(() => {
|
||||||
if (!paramsConfig) {
|
if (!paramsConfig?.length) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
console.log('renderFields---------');
|
console.log('renderFields---------');
|
||||||
@@ -123,7 +125,7 @@ const ParamsSettings: React.FC<ParamsSettingsProps> = forwardRef(
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}, [paramsConfig, intl, watchFields]);
|
}, [formFields, intl, watchFields]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form
|
<Form
|
||||||
|
|||||||
@@ -444,7 +444,7 @@ const GroundEmbedding: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
handleOnValuesChange(changeValues, allValues);
|
handleOnValuesChange(changeValues, allValues);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[handleOnValuesChange]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
useHotkeys(
|
useHotkeys(
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
setParams,
|
setParams,
|
||||||
form,
|
form,
|
||||||
watchFields,
|
watchFields,
|
||||||
|
formFields,
|
||||||
paramsConfig,
|
paramsConfig,
|
||||||
initialValues,
|
initialValues,
|
||||||
parameters,
|
parameters,
|
||||||
@@ -298,6 +299,7 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
<DynamicParams
|
<DynamicParams
|
||||||
ref={form}
|
ref={form}
|
||||||
watchFields={watchFields}
|
watchFields={watchFields}
|
||||||
|
formFields={formFields}
|
||||||
parametersTitle={
|
parametersTitle={
|
||||||
<div className="flex-between flex-center">
|
<div className="flex-between flex-center">
|
||||||
<span>
|
<span>
|
||||||
|
|||||||
@@ -431,16 +431,13 @@ const GroundReranker: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
setIsEmptyText(false);
|
setIsEmptyText(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onValuesChange = useCallback(
|
const onValuesChange = useCallback((changedValues: any, allValues: any) => {
|
||||||
(changedValues: any, allValues: any) => {
|
if (changedValues.model) {
|
||||||
if (changedValues.model) {
|
setTokenResult(null);
|
||||||
setTokenResult(null);
|
} else {
|
||||||
} else {
|
handleOnValuesChange(changedValues, allValues);
|
||||||
handleOnValuesChange(changedValues, allValues);
|
}
|
||||||
}
|
}, []);
|
||||||
},
|
|
||||||
[handleOnValuesChange]
|
|
||||||
);
|
|
||||||
|
|
||||||
useHotkeys(
|
useHotkeys(
|
||||||
HotKeys.SUBMIT,
|
HotKeys.SUBMIT,
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
setParamsConfig,
|
setParamsConfig,
|
||||||
form,
|
form,
|
||||||
watchFields,
|
watchFields,
|
||||||
|
formFields,
|
||||||
paramsConfig,
|
paramsConfig,
|
||||||
initialValues,
|
initialValues,
|
||||||
parameters,
|
parameters,
|
||||||
@@ -527,6 +528,7 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
<DynamicParams
|
<DynamicParams
|
||||||
ref={form}
|
ref={form}
|
||||||
watchFields={watchFields}
|
watchFields={watchFields}
|
||||||
|
formFields={formFields}
|
||||||
parametersTitle={
|
parametersTitle={
|
||||||
<div className="flex-between flex-center">
|
<div className="flex-between flex-center">
|
||||||
<span>
|
<span>
|
||||||
|
|||||||
@@ -366,6 +366,11 @@ export const useInitImageMeta = (props: MessageProps) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const formFields = useMemo(() => {
|
||||||
|
const fields = paramsConfig?.map((item) => item.name);
|
||||||
|
return fields?.join(',');
|
||||||
|
}, [paramsConfig]);
|
||||||
|
|
||||||
const handleOnModelChange = useCallback(
|
const handleOnModelChange = useCallback(
|
||||||
(val: string) => {
|
(val: string) => {
|
||||||
if (!val || val === parameters.model) return;
|
if (!val || val === parameters.model) return;
|
||||||
@@ -461,6 +466,7 @@ export const useInitImageMeta = (props: MessageProps) => {
|
|||||||
updateParamsConfig,
|
updateParamsConfig,
|
||||||
setParamsConfig,
|
setParamsConfig,
|
||||||
form,
|
form,
|
||||||
|
formFields,
|
||||||
watchFields,
|
watchFields,
|
||||||
paramsConfig,
|
paramsConfig,
|
||||||
initialValues,
|
initialValues,
|
||||||
|
|||||||
Reference in New Issue
Block a user