Skip to content

(perf) Syntax word wrap without line numbers repeatedly renders each source line #4176

Open

Description

@KRRT7

Syntax._get_syntax() currently calls console.render_lines(...) once per highlighted source line when word_wrap=True, even when line_numbers=False.

For syntax blocks without line numbers, continuation prefixes are not needed, so the selected highlighted lines can be joined and rendered/wrapped in one batch. This avoids repeatedly entering the generic console render pipeline.

Activity

  1. pavankumar-vh commented on Jul 2, 2026

    @pavankumar-vh

    I implemented the optimization in my fork on branch issue-4176-syntax-word-wrap-opt and pushed it here:

    https://github.com/pavankumar-vh/rich/tree/issue-4176-syntax-word-wrap-opt

    The change batches Syntax._get_syntax() word-wrap rendering when line_numbers=False, so it avoids calling console.render_lines() once per source line. I also added a regression test covering the call count, and the syntax test module passes locally.

    If someone with PR permissions wants to open the PR from that branch, the fix is ready.

  2. KRRT7 commented on Jul 2, 2026

    @KRRT7
    CollaboratorAuthor

    @pavankumar-vh there is a linked PR...

  3. pavankumar-vh commented on Jul 2, 2026

    @pavankumar-vh

    @KRRT7 Thanks for the heads-up! I wasn't aware there was already a linked PR when I commented. In that case, it's all good as-is. Appreciate you letting me know.

  4. KRRT7 commented on Jul 2, 2026

    @KRRT7
    CollaboratorAuthor

    @pavankumar-vh GitHub itself shows the linked PR, are you just asking your agent to go over open issues and resolve them?

  5. pavankumar-vh commented on Jul 2, 2026

    @pavankumar-vh

    @KRRT7 Yeah, pretty much 😅. I'm still very new to open source contributing and I'm honestly still figuring out how the GitHub workflow works. I saw the issue, worked on a fix, and didn't realize there was already a linked PR until you pointed it out. That's my mistake.

    I'm still learning things like how to spot existing work before jumping in, so thanks for the heads-up. I'll be more careful to check for linked PRs and ongoing discussions first.

  6. KRRT7 commented on Jul 2, 2026

    @KRRT7
    CollaboratorAuthor

    @pavankumar-vh no problem! feel free to join the discord if you're wanting to discuss anything or get advice!

  7. pavankumar-vh commented on Jul 2, 2026

    @pavankumar-vh

    @KRRT7 For sure, could you share me the invite link.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions