⚡ Bolt: Memoize LiquidStream messages to prevent O(N^2) renders#80
⚡ Bolt: Memoize LiquidStream messages to prevent O(N^2) renders#80teerthsharma wants to merge 1 commit into
Conversation
Co-authored-by: teerthsharma <78080953+teerthsharma@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What:
Extracted the inline message rendering logic in
LiquidStreaminto a newMessageItemcomponent and wrapped it inReact.memo(). Initialized the timestamp via auseStatehook with a lazy initializer to calculate it only once on mount.🎯 Why:$O(N^2)$ rendering bottleneck that makes the component progressively slower as the chat history grows. Furthermore,
The
messagesarray inLiquidStreamupdates frequently (simulating incoming data streams). Rendering the list items directly inside the.map()block meant that every new message appended to the array triggered a full re-render of all existing messages in the stream. This creates annew Date().toLocaleTimeString()was being called inline on every render, causing all previously recorded timestamps in the history to incorrectly update to the current time whenever a new message arrived or the user typed in the input box.📊 Impact:
🔬 Measurement:
LiquidStreamcomponent, and observe the React Profiler. You will see that previously renderedMessageItemcomponents do not re-render when new messages are added to the list.PR created automatically by Jules for task 15229860094832759570 started by @teerthsharma