github Zibbp/ganymede v1.1.6
v1.1.6 - Performance Improvements and Optimizations

latest releases: v3.0.1, v3.0.0, v2.3.2...
20 months ago

Changes

API

  • Chat playback now uses embedded badges if available in the chat file 053ae5c.
    • If both emotes and badges are embedded in a chat file, no requests to Twitch or any other external services is called when watching a video.
    • Use channel's specific badges instead of global versions in 53edd7b.
  • Improve performance of real time chat playback routes ebb4b4b.
    • Before this release, playback of large chat files would be slow and consume a lot of memory.
    • Improvements:
      • Revert back to Go's encoding/json package for better memory management.
      • Chat comments are sorted and stored in the cache using an interface on the initial request.
        • Before the comments were stored as a byte which needed to be unmarshalled each time which was terrible for performance.
      • A binary search is now used to find the index of a comment that is closest to the request offset time.
        • Before the comments were looped through to find the requested time. This was not efficient for large chat files.
      • The chat comment cache has a 10 minute expiration time that is refreshed each time a route that uses it is called.
      • The badge and emote routes have been improved to handle memory better.

Frontend

  • Add "loading chat" text when the real time chat player is loading Zibbp/ganymede-frontend@aff4dd0.
  • Add placeholder images for video thumbnails and channel profile images Zibbp/ganymede-frontend@666f657.
    • A blank image is used as a placeholder while the thumbnail is loading.
    • This results in a more pleasant experience when loading images as content is not jumping all over the page.
  • Styling fixes on the admin "watched channels" page Zibbp/ganymede-frontend@9d30103.

Information about Performance Improvements

How the real time chat player works

When navigating to a video to playback, the first two requests the real time chat player makes is for the emotes and badges. Each one of these requests opens the chat file and checks if there are embedded emotes and badges. If embedded images are found, those are sent back to the frontend chat player. If no images are found, the emotes or badges are fetched from various providers. This process, especially extracting the embedded images results in a temporary increase of ram usage as it has to load a large chat file (250mb) into memory and extract/process the embedded images which is a majority of the chat file size. Once the image are sent back to the client Go's garbage collector will free up the memory when it sees fit.

After the emotes and badges are loaded into the player, the first comments are fetched. Comments are fetched in interval of 10 seconds using this API route /api/v1/vod/id/chat?start=0&end=10. In the backend, this route will check if the comments are stored in the cache. If they are not then the chat file is opened, comments extracted, formatted, and placed into the cache for subsequent requests. Once placed or read from the cache, a binary search is used to find a comment's index which is closest to the requested start location. The index is then used to iterate up until the end location is satisfied.

Performance numbers

This test occurred locally using a 251mb chat file which has 3,379 embedded images.

Endpoint used: /chat/seek?start=12352&count=30.

Old Performance:

Initial Request: 19.5 seconds
Cached Requests: ~8 seconds

New Performance:

Initial Request: 17.4 seconds
Cached Requests: 50-60 milliseconds.

With a ~3x reduction of memory usage.

Summary

The initial chat request when starting a real time chat playback will still take some time as it has to open, unmarshall, and sort the 10's of thousands of comments. Once that is complete the comments are stored in a 10 minute cache. Any subsequent request that uses that chat file will pull the comments from the chat resulting in <100 millisecond response times of the requested chat comments.

Notice any issues or bugs with this release? Please open an issue.

Full Changelog: v1.1.5...v1.1.6

Don't miss a new ganymede release

NewReleases is sending notifications on new releases.