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

Memory and rendering improvements #752

Merged
merged 44 commits into from
Jul 31, 2023
Merged

Conversation

ScrubN
Copy link
Collaborator

@ScrubN ScrubN commented Jul 3, 2023

  • Use spans in SubstringToTextWidth and GetShapedTextPath
  • Allow reusing a single shaper object when measuring text
  • Get font reference in GetShapedTextPath instead of cloning the font
  • Short circuit SubstringToTextWidth to a faster Skia method when the message does not contain delimiters or RTL
  • Don't hide the renderoptions in GetFallbackFont
  • Add more debug attributes
  • Implement IDisposable on ChatRenderer, TwichEmote, ChatBadge, and CheerEmote to properly dispose of unmanaged resources instead of having to call GC.WaitForPendingFinalizers
  • Rename HighlightMessage -> HighlightIcons and make it a private field of ChatRenderer
  • Cache TwitchEmote codec values instead of repeatedly making the same extern calls
  • Less copying and repeated accessing when resizing badges
  • Return reference icon bitmaps instead of copied bitmaps to reduce redundant copying and disposing.
  • Cleanup FFmpegProcess class
  • Short circuit RemoveRestrictedComments when there are no restrictions
  • Do less allocations in RemoveRestrictedComments
  • Make string.ToLower() calls into string.Equals(..., StringComparison.OrdinalIgnoreCase)
  • Use StringBuilder.Replace instead of string.Replace when generating ffmpeg args
  • Do not uselessly render every previous comment when a render is starting at comment index 101 or later
  • Refactor HighlightIcons to use spans to allocate no strings on average and do less redundant checks
  • Add success check to TwitchEmote image decoding to throw an exception with a more descriptive message
  • Only report render progress every 3 ticks for less object creations
  • Replace concatenating formatted ToString's with a single formatted interpolated string
  • Cache the SKImageInfo for each sectionImage for less extern calls
  • Refactor bit prefix checking to do less allocations
  • Reduce allocations made by TimeSpanHFormat.Format
  • Reduce allocations made by the text chat serializer regarding timestamp formatting
  • Move GetShapedTextPath to SKPaintExtensions and cache SKPaint.GetFont reflection
  • Use a StringBuilder instead of concatenation when compiling message bodies
  • Make banned word regexes local to the relevant function instead of a private field
  • Fix ChatRender timestamps resetting after 24 hours
  • Make ChatRender timestamps almost free
  • Make gift-illus.png (highlight icon) fetching obey offline status
  • Make bitmaps immutable and use SKImage over SKBitmap for icons
    • Apparently these increase performance when calling SKCanvas.DrawBitmap/SKCanvas.DrawImage by sharing memory handles instead of copying
  • Fix HTML chat message timestamps resetting after 24 hours
  • Reduce memory allocated by the HTML chat serializer
  • Misc cleanup

@ScrubN ScrubN force-pushed the memory-improvements branch from ee07236 to 783d5c3 Compare July 7, 2023 05:58
@ScrubN
Copy link
Collaborator Author

ScrubN commented Jul 7, 2023

I don't know why I didn't try spans before using the StringPool, but the difference in performance is insane. The renderer is still bottlenecked by copying to ffmpeg though :(

ScrubN added 4 commits July 8, 2023 12:43
… use interpolated string handler format provider instead of ToString
…use custom TryGetTwitchEmote() methods instead of .Any() then .First()
…Formatted, create ToFormattedString<T>() for custom string formatting without boxing
@ScrubN ScrubN changed the title Render speed and memory improvements Memory and rendering improvements Jul 11, 2023
Why is string.Create not mentioned more in the docs??
ScrubN added 5 commits July 12, 2023 19:04
…rd regexes only in the needed scope, rename fields
…imestamp generation almost free, make TimeSpanHFormat.Format faster and allocate less, add non-boxing overload of TimeSpanHFormat.Format
…hing gift-illus.png, return SKImages from HighlightIcons

Apparently calling SKCanvas.DrawBitmap with immutable bitmaps and using SKCanvas.DrawImage where possible increase performance
Copy link
Collaborator Author

@ScrubN ScrubN left a comment

Choose a reason for hiding this comment

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

I need to stop making 1.5k line change PRs

@ScrubN ScrubN merged commit c7e6879 into lay295:master Jul 31, 2023
@ScrubN ScrubN deleted the memory-improvements branch July 31, 2023 03:03
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