Skip to content

Address performance problems for StructuredText code blocks#8

Merged
bisonbet merged 2 commits into
mainfrom
pr-39-streaming-perf
Jun 1, 2026
Merged

Address performance problems for StructuredText code blocks#8
bisonbet merged 2 commits into
mainfrom
pr-39-streaming-perf

Conversation

@bisonbet

Copy link
Copy Markdown
Owner

Cherry-picked from gonzalezreal/textual PR gonzalezreal#39

Improves reliability of StructuredText when rendering large code blocks and makes Textual more suited to streaming content.

@bisonbet

Copy link
Copy Markdown
Owner Author

@codex please review this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9bf43d8cc4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +37 to +38
.task(id: code) {
await model.tokenize(code: code, languageHint: languageHint, theme: theme)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include highlighter theme in tokenization task identity

When a code block is first rendered with .plain or another theme whose tokenProperties is empty, tokenize now intentionally skips Prism and stores only a single plain token; if the same view later receives a syntax-highlighting theme for the same code string, this .task(id: code) does not run again, so the block stays un-tokenized and cannot apply token colors. This affects apps that switch themes dynamically via highlighterTheme(_:); key the task on the tokenization inputs that now include the theme/tokenProperties (or otherwise retrigger tokenization when an empty-token theme changes to a highlighting theme).

Useful? React with 👍 / 👎.

@bisonbet

Copy link
Copy Markdown
Owner Author

@codex please fix the issues you noted in the comments

@chatgpt-codex-connector

Copy link
Copy Markdown

Summary

  • Updated HighlightedTextFragment so tokenization is keyed by the full tokenization-relevant input: code, language hint, and highlighter token properties. This retriggers tokenization when switching from .plain to a syntax-highlighting theme for the same code string.
  • Included the active highlighter theme in the highlight change observation so already-tokenized code is re-highlighted when the theme changes.
  • Updated the file overview comment to reflect the new tokenization identity behavior.
  • Committed the changes with commit 9164ba7 and created a follow-up PR titled “Fix highlighter tokenization identity.”

Testing

  • make format
  • git diff --check
  • ⚠️ swift test — blocked because SwiftPM dependency fetches from GitHub failed with CONNECT tunnel failed, response 403.
  • ⚠️ swift test --skip-update — blocked because SwiftPM still attempted dependency fetches from GitHub and failed with CONNECT tunnel failed, response 403.

View task →

@bisonbet bisonbet force-pushed the pr-39-streaming-perf branch from 9bf43d8 to 4b284b3 Compare June 1, 2026 19:46
@bisonbet bisonbet merged commit 41424ed into main Jun 1, 2026
@bisonbet bisonbet deleted the pr-39-streaming-perf branch June 1, 2026 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants