Skip to content
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

Improve memory performance for txt chat download #757

Merged
merged 3 commits into from
Jul 25, 2023

Conversation

jmSfernandes
Copy link
Contributor

@jmSfernandes jmSfernandes commented Jul 17, 2023

WHY
My use case includes running this cli to download twitch chats, in a constraint environment (e.g, Rapsberri Pi).

The tool is great, but for large streams (with a lot of messages) the memory footprint can be big.
for instance for:
https://www.twitch.tv/videos/1857424785
The tool takes around 510 mbs of memory (see images).

I was looking at the code, and I found out some points in which we could optimize.
For instance, emotes, and Badges information are not used for txt files.
And creating these instances takes a lot of memory.
With the proposed changes I was able to reduce the memory usage significantly, to around: 360mbs for that particular case.

I also added a quiet mode (-q) option to the CLI, since some users might not be interested in keeping track of the progress (for instance my case, were the process is automated and I'm not looking at the progress), and this also lowers the memory consumption.

Improve memory performance.
image
image

HOW

  • Add quiet mode option (-q).
  • Improve Datetime parsing.
  • Added conditions to verify what is the Ouput File format when converting comments.
  • Changed Comment's message body creation to use a StringBuilder to improve memory performance.
  • Change progress percentages List to an int array to be allocated in the stack and initialized at 0.
  • Change DownloadSection to return a List of Comments objects, and made the comments unification and sorting after all tasks are finished to avoid concurrency issues,

Note:
Hi this is my first attempt to contribute to this project, so I'm sorry if I overlooked something.

Improve memory performance.
@ScrubN
Copy link
Collaborator

ScrubN commented Jul 18, 2023

Improve Datetime parsing.

I can't tell exactly what this is referencing, could you help point it out?

Added conditions to verify what is the Ouput File format when converting comments.

I guess this is alright, though several people have requested mock chat badges in text chats so this may be partially undone in the future

Changed Comment's message body creation to use a StringBuilder to improve memory performance.

I spotted this myself the other day and it would have been implemented anyways by #752

Change progress percentages List to an int array to be allocated in the stack and initialized at 0.

Unless the stackalloc keyword is used, int[]s are still allocated on the heap, so this really only saves about 32B of overhead introduced by the List<T> class, though every bit of saved memory still counts

Thanks for the changes, though if it's alright I would like to push a few minor changes to fix some formatting or some missed opportunities for further optimization

@ScrubN ScrubN merged commit ab33c0b into lay295:master Jul 25, 2023
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