Performance: Streaming responses
Streaming responses impact how quickly users see partial data and how smoothly the UI updates during data loading.
Jump into concepts and practice - no test required
const stream = await chain.stream({ input: 'query' }); for await (const chunk of stream) { console.log(chunk.text); }
const response = await chain.invoke({ input: 'query' }); console.log(response.text);
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Full response wait | Single large DOM update | 1 reflow after full data | High paint cost at once | [X] Bad |
| Streaming response | Multiple small DOM updates | Multiple small reflows | Lower paint cost per update | [OK] Good |
streaming=True do in a LangChain LLM?streaming=True.streaming=True, which matches the official LangChain pattern.llm = OpenAI(streaming=True)
response = llm("Hello, how are you?")
print(response)llm = OpenAI()
llm("Tell me a joke.")
What is the likely fix?streaming=True when creating the LLM enables streaming output.