Skip to content

refactor: Allocate less in parseTwitchEmotes - #7187

Merged
pajlada merged 4 commits into
Chatterino:masterfrom
Nerixyz:refactor/emote-parsing
Aug 22, 2026
Merged

pajlada merged 4 commits into
Chatterino:masterfrom
Nerixyz:refactor/emote-parsing

Conversation

@Nerixyz

@Nerixyz Nerixyz commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

parseTwitchEmotes and appendTwitchEmoteOccurrences do some string parsing. Notably they split the emote range strings (<emote-id>:<ranges...>/<emote-id>:...) into owned QStrings. They don't have to do that.

This PR moves the parsing from using QStrings to QStringViews and using tokenize (lazy split) and splitOnce. Furthermore, the message indices are now stack-allocated if possible and use 16 bits (enough for Twitch messages).

One might think of a further optimization: Storing only the emote ID in TwitchEmoteOccurrence and resolving the part in the message later. But we do need the name for processing ignore phrases.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

Comment thread src/providers/twitch/TwitchIrc.cpp Outdated

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

Comment thread src/providers/twitch/TwitchIrc.cpp Outdated
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@pajlada
pajlada enabled auto-merge (squash) August 22, 2026 11:00
@pajlada
pajlada merged commit e16c23f into Chatterino:master Aug 22, 2026
18 checks passed
invisibl3cat pushed a commit to invisibl3cat/chatterino2 that referenced this pull request Aug 23, 2026
`parseTwitchEmotes` and `appendTwitchEmoteOccurrences` do some string
parsing. Notably they split the emote range strings
(`<emote-id>:<ranges...>/<emote-id>:...`) into owned `QString`s. They
don't have to do that.

This PR moves the parsing from using `QString`s to `QStringView`s and
using `tokenize` (lazy split) and `splitOnce`. Furthermore, the message
indices are now stack-allocated if possible and use 16 bits (enough for
Twitch messages).

Reviewed-by: pajlada <rasmus.karlsson@pajlada.com>
babicekmarek pushed a commit to babicekmarek/streamally-chatterino that referenced this pull request Sep 14, 2026
`parseTwitchEmotes` and `appendTwitchEmoteOccurrences` do some string
parsing. Notably they split the emote range strings
(`<emote-id>:<ranges...>/<emote-id>:...`) into owned `QString`s. They
don't have to do that.

This PR moves the parsing from using `QString`s to `QStringView`s and
using `tokenize` (lazy split) and `splitOnce`. Furthermore, the message
indices are now stack-allocated if possible and use 16 bits (enough for
Twitch messages).

Reviewed-by: pajlada <rasmus.karlsson@pajlada.com>
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