Skip to content

Commit fa4be63

Browse files
committed
use structuredClone to improve performance
1 parent f2127e9 commit fa4be63

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

src/app/utils.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export function runCodeOnInputListsInVM(
9898
let target = undefined;
9999
try {
100100
// copy args to ensure correctness of mapping
101-
target = func(...JSON.parse(JSON.stringify(args)))
101+
target = func(...structuredClone(args))
102102
} catch (err) {
103103
console.warn(`execution err ${err}`)
104104
}
@@ -179,7 +179,7 @@ export function baseTableToExtTable(table: any[], derivedFields: FieldItem[], al
179179
let args = inputTuples;
180180
if (func.length == baseCols.length * 2 + 1) {
181181
// avoid side effect, use the copy of the column when calling the function
182-
args = [...inputTuples, rowIdx, ...JSON.parse(JSON.stringify(baseCols))]
182+
args = [...inputTuples, rowIdx, ...structuredClone(baseCols)]
183183
}
184184

185185
target = func(...args);
@@ -257,7 +257,7 @@ export const assembleVegaChart = (
257257
let chartTemplate = getChartTemplate(chartType) as ChartTemplate;
258258
//console.log(chartTemplate);
259259

260-
let vgObj = JSON.parse(JSON.stringify(chartTemplate.template));
260+
let vgObj = structuredClone(chartTemplate.template);
261261

262262
for (const [channel, encoding] of Object.entries(encodingMap)) {
263263

@@ -412,7 +412,7 @@ export const assembleVegaChart = (
412412
}
413413

414414
// this is the data that will be assembled into the vega chart
415-
let values = JSON.parse(JSON.stringify(workingTable));
415+
let values = structuredClone(workingTable);
416416
values = values.map((r: any) => {
417417
let keys = Object.keys(r);
418418
let temporalKeys = keys.filter((k: string) => conceptShelfItems.some(concept => concept.name == k && (concept.type == "date" || concept.semanticType == "Year")));

src/views/ModelSelectionDialog.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,22 @@ export const ModelSelectionButton: React.FC<{}> = ({ }) => {
136136
data.forEach((modelConfig: any) => {
137137
const provider = modelConfig.endpoint;
138138
const model = modelConfig.model;
139+
140+
if (provider && model && !modelsByProvider[provider]) {
141+
modelsByProvider[provider] = [];
142+
}
139143

140144
if (provider && model && !modelsByProvider[provider].includes(model)) {
141145
modelsByProvider[provider].push(model);
142146
}
143147
});
144148

145149
setProviderModelOptions(modelsByProvider);
150+
146151
} catch (error) {
147152
console.error("Failed to fetch model options:", error);
148-
} finally {
149-
setIsLoadingModelOptions(false);
150-
}
153+
}
154+
setIsLoadingModelOptions(false);
151155
};
152156

153157
fetchModelOptions();
@@ -501,13 +505,18 @@ export const ModelSelectionButton: React.FC<{}> = ({ }) => {
501505
})}
502506
{newModelEntry}
503507
<TableRow>
504-
<TableCell colSpan={8} align="left" sx={{fontSize: "0.625rem"}}>
505-
Model configuration based on LiteLLM, <a href="https://docs.litellm.ai/docs/" target="_blank" rel="noopener noreferrer">check out supported endpoint / models here</a>.
506-
Models with limited code generation capabilities (e.g., llama3.2) may fail frequently to derive new data.
508+
<TableCell colSpan={8} align="left" sx={{ '& .MuiTypography-root': { fontSize: "0.625rem" } }}>
509+
<Typography>
510+
Model configuration based on LiteLLM, <a href="https://docs.litellm.ai/docs/" target="_blank" rel="noopener noreferrer">check out supported endpoint / models here</a>.
511+
If using custom providers that are compatible with the OpenAI API, choose 'openai' as the provider.
512+
</Typography>
513+
<Typography>
514+
Models with limited code generation capabilities (e.g., llama3.2) may fail frequently to derive new data.
515+
</Typography>
507516
</TableCell>
508517
</TableRow>
509-
</TableBody>
510-
</Table>
518+
</TableBody>
519+
</Table>
511520
</TableContainer>
512521

513522
return <>

0 commit comments

Comments
 (0)