Performance: OpenAI embeddings
MEDIUM IMPACT
This concept affects the speed of API calls and the responsiveness of embedding-based search or similarity features in the frontend.
let debounceTimeout; inputElement.addEventListener('input', (e) => { clearTimeout(debounceTimeout); debounceTimeout = setTimeout(async () => { const embedding = await getEmbedding(e.target.value); updateSearchResults(embedding); }, 300); });
async function getEmbedding(text) { return await openai.createEmbedding({ model: 'text-embedding-3-large', input: text }); } // Called on every keystroke inputElement.addEventListener('input', async (e) => { const embedding = await getEmbedding(e.target.value); updateSearchResults(embedding); });
| Pattern | API Calls | Network Wait | UI Blocking | Verdict |
|---|---|---|---|---|
| Call on every keystroke | Many (1 per keystroke) | High | Blocks UI frequently | [X] Bad |
| Debounced calls | Few (after pause) | Low | Minimal UI blocking | [OK] Good |
| Sequential large batch calls | Many | Very High | Blocks UI for seconds | [X] Bad |
| Parallel batch calls | Many | Medium | Less UI blocking | [OK] Good |
| No caching repeated queries | Duplicates | Medium | Unnecessary blocking | [X] Bad |
| Cached repeated queries | Single per query | Low | No blocking | [OK] Good |