Skip to content

Studio: ask the Hub only for the first page a search reads - #18994

Merged
danielhanchen merged 3 commits into
mainfrom
perf/r39-hub-first-page-limit
Nov 23, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
perf/r39-hub-first-page-limit

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Problem

A typed model search (Model hub, composer model picker, export page, voice tab, embedding picker) fills its first page of 48 rows by reading at most MAX_RAW_ITEMS_PER_BATCH (192) rows. Several of the listings it reads pass no limit to listModels, so @huggingface/hub asks for limit=500 and the Hub answers with 500 fully expanded rows (safetensors, config, gguf, tags, ...) before the first page can show:

  • the general listing of mergedModelIterator (every typed search),
  • the Unsloth-only typed search (orgSearch),
  • createChannelIterator when the caller sets no limit (channel lists, and the newest listing of the Latest sort),
  • providerUnslothFirstIterator for a model maker's name (qwen, google, meta, ...): one listing per Unsloth search term plus one per maker org, while take() reads only PROVIDER_POOL (100) rows of each before ranking.

For qwen3 the general listing is 7.7 MB of JSON (1.8 MB on the wire) for 500 rows, of which the first page reads at most 192.

An SDK limit cannot fix this: it ends the listing after that many rows, and these listings must keep paging for infinite scroll and for the maker groups' tails.

Change

makeSortFetch takes an optional firstPageLimit. On the first request of a listing (no cursor), it lowers limit to that value. The Hub's next link repeats the request's limit, so on later pages (with cursor) it puts back the limit the SDK asked for (500). Only the first request of the listing gets smaller: the rows, their order and the later pages stay the same.

  • mergedModelIterator general listing: 192 on its first request.
  • Unsloth-only typed search: 192.
  • createChannelIterator with no caller limit: 192. Calls that already pass a limit (fetchChannelFirstPage at 192, the Latest trending pool at 100) keep it, and the SDK still ends them there.
  • providerUnslothFirstIterator listings: PROVIDER_POOL (100). The tail after the pool continues on the next page.

Listings that already set a small limit (the Unsloth pass of a typed search at 3, the feed first pages, the trending pool) and the listings this PR does not touch (plain browse, owner listings, priority listing) send the same requests as before.

Why 192 is enough: the first batch stops at 192 rows scanned. In mergedModelIterator each general row it skips as a repeat is one of the Unsloth rows already counted, so the batch never reads more than 192 general rows. A maker search reads 100 rows from each listing before it yields anything.

Checked on the live Hub

Anonymous GETs with the same expand fields Studio sends. For each listing, the capped first page was compared with the 500-row page, and the capped page's next link (limit set back to 500) was compared with the 500-row page plus its own next page:

listing cap rows compared first page = leading rows (whole row JSON) continuation = same order
search=coder, downloads 192 692 yes yes
search=coder, createdAt (composer, Latest) 192 692 yes yes
search=qwen3, downloads 192 692 yes yes
search=llama, downloads 192 692 yes yes
author=unsloth search=qwen (maker qwen) 100 411 yes yes
author=Qwen (maker qwen) 100 469 yes yes
author=unsloth search=gemma (maker google) 100 161 yes yes
author=google (maker google) 100 600 yes yes

Each next link from the Hub carried the capped limit (limit=192 or limit=100), which is why later pages put back 500.

I also ran the hook itself through 12 batches (576 rows) on main and on this PR for coder and for maker qwen. Both give the same 576 rows in the same order.

Results

I ran the shipped hook in Node (main and this PR, with React stubbed) against the live Hub, interleaving main, this PR and main again (A/A), 3 runs each. Time is from the start of the search to the first batch of 48 rows. MB is the JSON the requests of that search downloaded. The first-page rows were identical in every run of all three arms.

search main main (A/A) this PR MB main MB this PR
Model hub coder 475 ms (407 to 484) 470 ms (424 to 606) 292 ms (266 to 313) 5.06 2.36
Model hub qwen3 619 ms (497 to 725) 632 ms (593 to 666) 292 ms (256 to 405) 7.73 3.04
Model hub llama 298 ms (284 to 320) 296 ms (278 to 321) 227 ms (180 to 266) 1.53 0.69
Model hub qwen (maker) 294 ms (283 to 312) 314 ms (272 to 382) 183 ms (167 to 233) 5.43 1.54
Model hub google (maker) 222 ms (179 to 309) 327 ms (261 to 382) 268 ms (227 to 400) 2.66 1.60
Composer picker coder (Latest) 359 ms (331 to 414) 344 ms (326 to 411) 201 ms (195 to 280) 4.34 1.66
Model hub coder, Unsloth only 189 ms (115 to 226) 158 ms (128 to 161) 184 ms (151 to 216) 0.34 0.34

Both arms send the same number of requests for each search. For google the time difference is inside the A/A spread. Its largest listing (unsloth gemma, 161 rows) is only a little smaller at 100 rows, so the bytes still drop but the time does not. The Unsloth-only coder search has 4 rows, so nothing changes there.

Compressed size on the wire for the first request:

listing main (limit 500) this PR
search=coder 1.19 MB 0.41 MB (192)
search=qwen3 1.83 MB 0.82 MB (192)
author=Qwen 0.39 MB 0.13 MB (100)
author=unsloth search=qwen 0.47 MB 0.12 MB (100)

The host has a fast link to the Hub, so on slower connections the time saved should be larger.

Trade-off: scrolling a typed search past 192 rows now needs one more request (the next page is fetched at row 192 rather than at row 500). Rows and order do not change. In the 576-row runs above, main and this PR downloaded 8.41 MB and 6.62 MB for coder, and 5.43 MB each for qwen.

Tests

New tests/hub-search-first-page-limit.test.ts runs the shipped hook with the real @huggingface/hub listModels against a fake Hub that pages like the real one (honours limit and cursor, and its next link repeats the request's limit). Each test also compares the full output with a Hub serving 500-row pages, which is what main reads.

  • A typed search asks for 192 general rows first and 500 per page after that. The Unsloth pass still asks for 3. All 702 rows come out in the same order, and the second page starts right after the first page's last row.
  • A maker search asks for 100 rows first from the Unsloth term listing and from the maker org, then 500 on the next page. The output matches the uncapped run.
  • The Unsloth-only typed search and a channel listing ask for 192 first. A 600-row channel pages through unchanged.
  • Listings that already set a limit keep it: fetchChannelFirstPage sends one request at 192 and no next page, the Latest trending pool stays at 100, and a plain browse still asks for 500.

All 4 fail on main.

Two assertions in tests/hub-search-listing-overlap.test.ts (from #18477) pinned the old first request at 500: the general listing of a typed search, and the newest listing of the Latest sort. They now expect 192.

Frontend tests matching hub, search, picker, channel, feed, merge-task, embedding, export and voice: 1347 passed on this PR and 1343 on main (the 4 new tests make the difference), no failures on either. tsc (app and tests) is clean on both, and eslint on the changed files is clean.

Open-ended Hub listings (the general listing of a typed search, the
Unsloth-only typed search, channel listings with no caller limit, and the
model maker listings) asked for 500 expanded rows on their first request
while the first batch reads at most 192 (100 per maker listing).

makeSortFetch now takes a firstPageLimit: the first request (no cursor)
asks for that many rows, and later pages put back the SDK's page size, so
the listing keeps paging with the same rows in the same order.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-23T08:38:07.279082Z
We couldn’t complete this review. Comment @codex review to try again.
27ee5de Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: e8a2f3b415

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 23, 2026
@danielhanchen danielhanchen self-assigned this Nov 23, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 27ee5def8b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen marked this pull request as ready for review November 23, 2026 08:37
@danielhanchen
danielhanchen merged commit 918f3c8 into main Nov 23, 2026
@danielhanchen
danielhanchen deleted the perf/r39-hub-first-page-limit branch November 23, 2026 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant