Skip to content

Commit

Permalink
Improve memory performance for txt chat download (#757)
Browse files Browse the repository at this point in the history
* Add Quiet Mode.
Improve memory performance.

* Further reduce allocations

---------

Co-authored-by: ScrubN <72096833+ScrubN@users.noreply.github.com>
  • Loading branch information
jmSfernandes and ScrubN authored Jul 25, 2023
1 parent ee209a5 commit ab33c0b
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 110 deletions.
5 changes: 4 additions & 1 deletion TwitchDownloaderCLI/Modes/Arguments/ChatDownloadArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ public class ChatDownloadArgs
[Option("chat-connections", Default = 4, HelpText = "Number of downloading connections for chat")]
public int ChatConnections { get; set; }

[Option('q', "quiet", Default = false, HelpText = "Suppresses progress console output")]
public bool Quiet { get; set; }

[Option("temp-path", Default = "", HelpText = "Path to temporary folder to use for cache.")]
public string TempFolder { get; set; }
}
}
}
1 change: 1 addition & 0 deletions TwitchDownloaderCLI/Modes/DownloadChat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ private static ChatDownloadOptions GetDownloadOptions(ChatDownloadArgs inputOpti
Compression = inputOptions.Compression,
TimeFormat = inputOptions.TimeFormat,
ConnectionCount = inputOptions.ChatConnections,
Quiet = inputOptions.Quiet,
BttvEmotes = (bool)inputOptions.BttvEmotes!,
FfzEmotes = (bool)inputOptions.FfzEmotes!,
StvEmotes = (bool)inputOptions.StvEmotes!,
Expand Down
12 changes: 6 additions & 6 deletions TwitchDownloaderCore/Chat/ChatText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ public static async Task SerializeAsync(string filePath, ChatRoot chatRoot, Time
await using var sw = new StreamWriter(filePath);
foreach (var comment in chatRoot.comments)
{
string username = comment.commenter.display_name;
string message = comment.message.body;
var username = comment.commenter.display_name;
var message = comment.message.body;
if (timeFormat == TimestampFormat.Utc)
{
var timestamp = comment.created_at.ToString("yyyy'-'MM'-'dd HH':'mm':'ss 'UTC'");;
await sw.WriteLineAsync($"[{timestamp}] {username}: {message}");
var timestamp = comment.created_at;
await sw.WriteLineAsync($"[{timestamp:yyyy'-'MM'-'dd HH':'mm':'ss 'UTC'}] {username}: {message}");
}
else if (timeFormat == TimestampFormat.UtcFull)
{
var timestamp = comment.created_at.ToString("yyyy'-'MM'-'dd HH':'mm':'ss.fff 'UTC'");;
await sw.WriteLineAsync($"[{timestamp}] {username}: {message}");
var timestamp = comment.created_at;
await sw.WriteLineAsync($"[{timestamp:yyyy'-'MM'-'dd HH':'mm':'ss.fff 'UTC'}] {username}: {message}");
}
else if (timeFormat == TimestampFormat.Relative)
{
Expand Down
Loading

0 comments on commit ab33c0b

Please sign in to comment.