Skip to content

Commit 91fc30c

Browse files
authored
[PERF][BUGFIX] Improve models load (#468)
* avoid fetching models on each request * avoid page errors when list datasets endpoint fails * fix: read HF image format properly on export * chore: increase duckDB number of threads
1 parent 54a1282 commit 91fc30c

File tree

9 files changed

+392
-324
lines changed

9 files changed

+392
-324
lines changed

src/features/add-column/form/execution-form.tsx

Lines changed: 215 additions & 182 deletions
Large diffs are not rendered by default.

src/features/import/import-from-hub.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@ const DatasetSearch = component$(
190190
return await listHubDatasets(query);
191191
});
192192

193+
const noResultsFound = useComputed$(() => {
194+
return (
195+
searchQueryDebounced.value.length >= 3 && datasets.value.length === 0
196+
);
197+
});
198+
193199
const handleChangeDataset$ = $((value: string | string[]) => {
194200
const selected = value as string;
195201
selectedDataset.value = selected ?? '';
@@ -277,6 +283,11 @@ const DatasetSearch = component$(
277283
))}
278284
</Select.Popover>
279285
</Select.Root>
286+
{noResultsFound.value && (
287+
<div class="text-foreground text-sm mt-1">
288+
No results found. Please, try another search query.
289+
</div>
290+
)}
280291
</div>
281292
);
282293
},

src/loaders/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1+
export * from './config';
12
export * from './dataset';
23
export * from './session';
3-
export * from './config';
4-
export * from './hub-models';

src/routes/home/index.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ import { MainSidebarButton } from '~/features/main-sidebar';
2020
import { Username } from '~/features/user/username';
2121
import { useSession } from '~/loaders';
2222
import { ActiveDatasetProvider, useDatasetsStore } from '~/state';
23+
import {
24+
type TrendingModel,
25+
useTrendingHubModels,
26+
} from '~/usecases/models-info.usecase';
2327
import { runAutoDataset } from '~/usecases/run-autodataset';
24-
import { useTrendingModelsContext } from './layout';
2528

2629
const runAutoDatasetAction = server$(async function* (
2730
instruction: string,
@@ -40,17 +43,24 @@ const runAutoDatasetAction = server$(async function* (
4043
});
4144

4245
export default component$(() => {
46+
const fetchTrendingModels = useTrendingHubModels();
4347
const session = useSession();
4448
const nav = useNavigate();
4549
const searchOnWeb = useSignal(false);
4650
const prompt = useSignal('');
4751
const currentStep = useSignal('');
48-
const trendingModels = useTrendingModelsContext();
52+
53+
const trendingModels = useSignal<TrendingModel[]>([]);
54+
4955
const textAreaElement = useSignal<HTMLTextAreaElement>();
5056
const { clearActiveDataset } = useDatasetsStore();
5157

52-
useTask$(() => {
58+
useTask$(async () => {
5359
clearActiveDataset();
60+
61+
if (trendingModels.value.length === 0) {
62+
trendingModels.value = await fetchTrendingModels();
63+
}
5464
});
5565

5666
const creationFlow = useStore({
@@ -354,7 +364,7 @@ export default component$(() => {
354364
<p class="text-sm text-center w-full lg:text-left lg:w-fit">
355365
Trending for vibe testing:
356366
</p>
357-
{trendingModels.map((model) => (
367+
{trendingModels.value?.map((model) => (
358368
<div
359369
key={model.id}
360370
class="flex items-center p-1 gap-1 font-mono"

src/routes/home/layout.tsx

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,7 @@ import {
88

99
import { ModalsProvider } from '~/components';
1010
import { MainSidebar } from '~/features/main-sidebar';
11-
import {
12-
type ClientConfig,
13-
type Model,
14-
useClientConfig,
15-
useHubModels,
16-
useTrendingHubModels,
17-
} from '~/loaders';
11+
import { type ClientConfig, useClientConfig } from '~/loaders';
1812
import { ActiveDatasetProvider } from '~/state';
1913

2014
export * from '~/loaders';
@@ -25,28 +19,10 @@ export const useConfigContext = () => {
2519
return useContext(configContext);
2620
};
2721

28-
export const modelsContext = createContextId<Model[]>('models.context');
29-
30-
export const useModelsContext = () => {
31-
return useContext(modelsContext);
32-
};
33-
34-
export const trendingModelsContext = createContextId<Model[]>(
35-
'trending-models.context',
36-
);
37-
38-
export const useTrendingModelsContext = () => {
39-
return useContext(trendingModelsContext);
40-
};
41-
4222
export default component$(() => {
4323
const config = useClientConfig();
44-
const models = useHubModels();
45-
const trendingModels = useTrendingHubModels();
4624

4725
useContextProvider(configContext, config.value);
48-
useContextProvider(modelsContext, models.value);
49-
useContextProvider(trendingModelsContext, trendingModels.value);
5026

5127
return (
5228
<ModalsProvider>

src/services/db/duckdb.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const {
66
} = appConfig;
77

88
const duckDB = await DuckDBInstance.create(duckDb);
9+
const duckDBThreads = 4;
910

1011
export const dbConnect = async () => {
1112
return await duckDB.connect();
@@ -39,7 +40,7 @@ await connectAndClose(async (db) => {
3940
LOAD gsheets;
4041
LOAD nanoarrow;
4142
42-
SET threads=2;
43+
SET threads=${duckDBThreads};
4344
SET temp_directory = '${duckDB}_duckdb_swap';
4445
SET memory_limit='128GB';
4546
SET max_temp_directory_size = '256GB';

src/services/repository/tables/list-table-rows.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,11 @@ const readImageBuffer = (data: any): Uint8Array | undefined => {
9696
return new Uint8Array(imageData);
9797
} else if (
9898
imageData &&
99+
// Hugging Face format
99100
typeof imageData === 'object' &&
100-
'buffer' in imageData
101+
'bytes' in imageData
101102
) {
102-
return new Uint8Array(imageData.buffer);
103+
return new Uint8Array(imageData.bytes);
103104
} else {
104105
throw new Error(`Invalid image data format`);
105106
}

src/usecases/list-hub-datasets.usecase.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@ export const useListHubDatasets = () =>
1212
const session = useServerSession(this);
1313
const query = searchQuery.trim();
1414

15-
const datasets = await listDatasets({
16-
query,
17-
accessToken: session.token,
18-
limit: 10,
19-
});
15+
try {
16+
const datasets = await listDatasets({
17+
query,
18+
accessToken: session.token,
19+
limit: 10,
20+
});
2021

21-
return datasets.map((dataset) => dataset.name);
22+
return datasets.map((dataset) => dataset.name);
23+
} catch (error) {
24+
console.error('Error listing datasets:', error);
25+
return [];
26+
}
2227
});
2328

2429
export const useListDatasetDataFiles = () =>

0 commit comments

Comments
 (0)