Skip to content

feat: improve memory usage of FFZ badges#7126

Open
Nerixyz wants to merge 2 commits into
Chatterino:masterfrom
Nerixyz:chore/ffz-memory-usage
Open

feat: improve memory usage of FFZ badges#7126
Nerixyz wants to merge 2 commits into
Chatterino:masterfrom
Nerixyz:chore/ffz-memory-usage

Conversation

@Nerixyz

@Nerixyz Nerixyz commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

FFZ badges consume a decent amount of memory in Chatterino. Before this PR, they consumed 18.4 MiB.

We can do two cheap optimizations that cut the use in half:

  • Use QVarLengthArray to store the badges for a user instead of std::set. std::set always allocates, even if there's only one badge. Since most users only have one, we create many small allocations. With QVarLengthArray<T, N>, N elements are stored inline. This reduced the memory usage to 11.9 MiB.
  • Use boost::unordered_flat_map instead of std::unordered_map. Because of relaxed requirements for the Boost map, it doesn't need to store as much auxiliary data. This reduced the memory usage to 9.3 MiB.

A further optimization could be the use of a boost::container::flat_multimap<std::string, int>. This gets us to 4.6 MiB. I haven't measured the performance of this. We'd have to assume that FFZ returns us unique users per badge. The comparison with QString for the lookup can be done by comparing QString < QLatin1StringView (as we know badge IDs are latin1).

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.

1 participant