Skip to content

content: Handle keyword highlighting in code blocks #1737

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

rajveermalviya
Copy link
Member

Take 2 of #1707

Fixes: #1695

Screenshots when commits based on top of #1694:

Flutter Web
image image

The code block spans with `hll` (and `highlight` used for search
keyword highlighting) classes can be nested inside other types of
code block spans. So add support for parsing those types of spans.
@gnprice
Copy link
Member

gnprice commented Jul 23, 2025

Thanks!

I see some timings, including for this PR, in #1707 (comment), which are very helpful. Can you repeat those timings atop main, without this PR's changes?

Those show about 2ms for parsing a long code block. That's tolerable if we can't easily do better; but it's nontrivial, being a sizable fraction of a frame interval. So I'm curious how much of that is a regression due to what's added in this PR, and how much of it is already in our current logic.

@rajveermalviya
Copy link
Member Author

Here are the timings for main and this PR when running the release version of the app on my Android device running Lineage OS 22.2 (Android 15).

Current main

I/flutter ( 7160): parseCodeBlock took 1875us
I/flutter ( 7160): CodeBlock.build took 168us
I/flutter ( 7160): parseCodeBlock took 2838us
I/flutter ( 7160): CodeBlock.build took 383us
I/flutter ( 7160): parseCodeBlock took 1519us
I/flutter ( 7160): CodeBlock.build took 287us
I/flutter ( 7160): parseCodeBlock took 2497us
I/flutter ( 7160): CodeBlock.build took 214us
I/flutter ( 7160): parseCodeBlock took 1868us
I/flutter ( 7160): CodeBlock.build took 183us
I/flutter ( 7160): parseCodeBlock took 1793us
I/flutter ( 7160): CodeBlock.build took 200us
I/flutter ( 7160): parseCodeBlock took 2135us
I/flutter ( 7160): CodeBlock.build took 243us
I/flutter ( 7160): parseCodeBlock took 2276us
I/flutter ( 7160): CodeBlock.build took 212us
I/flutter ( 7160): parseCodeBlock took 1556us
I/flutter ( 7160): CodeBlock.build took 250us
I/flutter ( 7160): parseCodeBlock took 2206us
I/flutter ( 7160): CodeBlock.build took 386us

Tree (this PR)

I/flutter (25604): parseCodeBlock took 1542us
I/flutter (25604): CodeBlock.build took 192us
I/flutter (25604): parseCodeBlock took 1401us
I/flutter (25604): CodeBlock.build took 228us
I/flutter (25604): parseCodeBlock took 1884us
I/flutter (25604): CodeBlock.build took 207us
I/flutter (25604): parseCodeBlock took 1772us
I/flutter (25604): CodeBlock.build took 211us
I/flutter (25604): parseCodeBlock took 1993us
I/flutter (25604): CodeBlock.build took 235us
I/flutter (25604): parseCodeBlock took 2388us
I/flutter (25604): CodeBlock.build took 362us
I/flutter (25604): parseCodeBlock took 1716us
I/flutter (25604): CodeBlock.build took 219us
I/flutter (25604): parseCodeBlock took 2008us
I/flutter (25604): CodeBlock.build took 366us
I/flutter (25604): parseCodeBlock took 2239us
I/flutter (25604): CodeBlock.build took 373us
I/flutter (25604): parseCodeBlock took 1720us
I/flutter (25604): CodeBlock.build took 262us

So looks like that the parsing step is faster with this PR, 1.4/1.8/2.3ms (min/avg/max) where on main it takes 1.5/2.0/2.8ms. While rendering step, this PR takes 192/265/373us and main takes 168/252/386us, so main is slightly faster there.
Overall when combining both timings, this PR takes 1.6/2.1/2.7ms and main takes 1.8/2.3/3.2ms.

@gnprice
Copy link
Member

gnprice commented Jul 23, 2025

Great, thanks for checking that. So there's potentially room for improvement in our parse times for code blocks (as there might be for other content too) — but this PR moves that in the right direction.

(And I think it's not currently a priority to try to optimize that parse time any further — it's tolerable that a giant message might take a couple of ms when it first appears.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintainer review PR ready for review by Zulip maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

search: Highlight keyword matches in code blocks
3 participants