[PR #22299] [CLOSED] perf: replace O(n*m) custom model matching with O(n+m) dict lookups #65454

Closed
opened 2026-05-06 11:17:28 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/22299
Author: @Classic298
Created: 3/6/2026
Status: Closed

Base: devHead: perf/dict-lookup-custom-models


📝 Commits (3)

📊 Changes

1 file changed (+64 additions, -48 deletions)

View changed files

📝 backend/open_webui/utils/models.py (+64 -48)

📄 Description

The custom model matching loop in get_all_models() iterated all base models for every custom model, resulting in O(n*m) complexity. This also rebuilt a list of model IDs per custom model in the elif branch.

Replace the nested loops with two dict indices (exact ID and Ollama base-name) built once, then look up each custom model in O(1). Also replace the per-iteration list comprehension for existing model IDs with a precomputed set.

Behavior is identical - same matching logic, same precedence.

Contributor License Agreement

By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.

Note

Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/22299 **Author:** [@Classic298](https://github.com/Classic298) **Created:** 3/6/2026 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `perf/dict-lookup-custom-models` --- ### 📝 Commits (3) - [`50e2af7`](https://github.com/open-webui/open-webui/commit/50e2af7e4862b87bcb46d437475ec6327843f4a3) perf: replace O(n*m) custom model matching with O(n+m) dict lookups - [`79d308c`](https://github.com/open-webui/open-webui/commit/79d308cba8703850802efdc952ce7bf7c235a62e) perf(models): use dict lookups for custom-to-base model matching - [`1e22b92`](https://github.com/open-webui/open-webui/commit/1e22b92fe09f5f565c929fa98fa0e07eaedb8299) Merge branch 'perf/dict-lookup-custom-models' of https://github.com/Classic298/open-webui into perf/dict-lookup-custom-models ### 📊 Changes **1 file changed** (+64 additions, -48 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/utils/models.py` (+64 -48) </details> ### 📄 Description The custom model matching loop in get_all_models() iterated all base models for every custom model, resulting in O(n*m) complexity. This also rebuilt a list of model IDs per custom model in the elif branch. Replace the nested loops with two dict indices (exact ID and Ollama base-name) built once, then look up each custom model in O(1). Also replace the per-iteration list comprehension for existing model IDs with a precomputed set. Behavior is identical - same matching logic, same precedence. ### Contributor License Agreement <!-- 🚨 DO NOT DELETE THE TEXT BELOW 🚨 Keep the "Contributor License Agreement" confirmation text intact. Deleting it will trigger the CLA-Bot to INVALIDATE your PR. --> By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. > [!NOTE] > Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-05-06 11:17:29 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#65454