-
Notifications
You must be signed in to change notification settings - Fork 3
perf(frontend): memoize chat items to stop re-parsing markdown on every token #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+107
−22
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1f4c600
perf(frontend): memoize chat item rendering to stop re-parsing markdo…
b37907e
fix(review): address Greptile findings on #150
lucastononro aceebec
merge: PR #148 — dedupe EventSource, share one session SSE stream via…
lucastononro 4a4fbc9
chore(staging): ledger row — PR #148
lucastononro 3e48748
Merge branch 'staging-v0.0.5' into fix/98-memoize-chat
lucastononro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # Manual test: chat item memoization & streaming (PR #150) | ||
|
|
||
| PR #150 memoizes `ChatItemView` (frontend/src/app/page.tsx) and hoists the | ||
| `remarkGfm` plugin array so markdown bubbles stop re-parsing on every streamed | ||
| token. Each item also receives a per-item `isStreaming` boolean (not the shared | ||
| streaming-item id), so when a stream starts or ends only the affected bubble | ||
| re-renders. There is no frontend unit-test infrastructure in this repo, so | ||
| verify the behavior manually as follows. | ||
|
|
||
| ## Setup | ||
|
|
||
| 1. Start the stack (backend + frontend) as usual, e.g. `docker compose up` | ||
| or `cd frontend && npm ci && npm run dev` against a running backend. | ||
| 2. Open the app in Chrome and open a session with an existing chat history | ||
| (or create one and send a few messages first, including at least one | ||
| assistant reply containing markdown: headings, a table, a code block). | ||
| 3. Open Chrome DevTools → install/enable **React Developer Tools** → | ||
| Profiler tab → gear icon → check **"Record why each component rendered"** | ||
| and enable **"Highlight updates when components render"** in the settings. | ||
|
|
||
| ## Test 1 — only the streaming bubble re-renders per token | ||
|
|
||
| 1. Start Profiler recording. | ||
| 2. Send a new message and let the assistant stream a long reply. | ||
| 3. Stop recording after the stream ends. | ||
|
|
||
| **Expected:** | ||
| - During token updates, render highlights flash only around the streaming | ||
| assistant bubble, not around earlier chat bubbles. | ||
| - In the Profiler flamegraph, prior `ChatItemView` instances show | ||
| "Did not render" / memo bailout for the token-update commits. | ||
| - At the stream **start** and **end** commits, only the streaming item | ||
| re-renders (its `isStreaming` prop flips); other items still bail out — | ||
| this is the per-item boolean fix from the Greptile review. | ||
|
|
||
| ## Test 2 — markdown is not re-parsed in old bubbles | ||
|
|
||
| 1. With a history containing a large markdown reply (table + code block), | ||
| start streaming a new reply. | ||
| 2. In the Profiler, select the old markdown bubble's `ChatItemView`. | ||
|
|
||
| **Expected:** it reports no renders during the stream. If it re-rendered | ||
| every token (the pre-PR behavior), `ReactMarkdown` would re-parse its content | ||
| each time — visible as jank/CPU in the Performance tab on long histories. | ||
|
|
||
| ## Test 3 — streaming caret behaves correctly | ||
|
|
||
| 1. Watch the streaming assistant bubble while tokens arrive. | ||
|
|
||
| **Expected:** | ||
| - A blinking caret is shown at the end of the streaming bubble only. | ||
| - When the stream finishes, the caret disappears from that bubble. | ||
| - No other bubble ever shows a caret. | ||
|
|
||
| ## Test 4 — no visual/behavioral regressions | ||
|
|
||
| Quickly sanity-check every chat item type still renders: | ||
| user messages (incl. file pills and @-mentions), assistant markdown | ||
| (GFM tables/strikethrough/task lists must still render — this exercises the | ||
| hoisted `CHAT_MARKDOWN_PLUGINS`), tool cards, sub-agent cards, clarification | ||
| cards, and error items. Scroll through an existing long session to confirm. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.