Rewrite IrcParser, pass through raw text to IrcMessage and fix other issues #230
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes
Major
IrcParser
IrcMessage
back into its raw format by the message handler right after it was parsedMinor
Tuple<T1, T2>
(which is a legacy class type, and should not be used) inThrottlingService
used by queue with(T1, T2)
akaValueTuple<T1, T2>
Rationale
I accidentally stumbled upon https://github.com/jprochazk/twitch-irc-benchmarks and was alerted of, as was initially believed, exceedingly poor performance of the Twitch IRC message parser of this library making it a contributor to global warming given the popularity and truly horrifying numbers.
After finishing reference implementation (https://github.com/neon-sunset/feetlicker) to compete in the benchmark, discussing with maintainers details in Discord and benchmarking TwitchLib's
IrcParser
, it turned out to be a mistake.TwitchLib's parser implementation was already competitively fast. The cause for such high execution time and memory traffic numbers (completely deadlocking GC, 15GB of memory traffic in scope of parsing 1000 forsen stream messages) was the fact that the benchmark was measuring parse + handle message cost.
Upon further inspection, the following inefficiencies were identified:
IrcMessage
after successfully parsing it, the raw text was getting immediately rebuilt back withGenerateToString()
instead (fixed in this PR)IrcParser
style to avoid intermediate allocations (follow-up work)MessageEmoteCollection.Add
appears to be extremely expensive both in terms of CPU and memory according to profiler. It dominates the execution time and needs further analysis (follow-up work)Numbers
Setup
Parse Message
Base:
PR:
Parse and check failed auth
Note: this specifically tests for a degenerate case of receiving long message, which are commonplace now.
Base:
PR: