stream.hls_playlist: refactor M3U8Parser#4540
Merged
Merged
Conversation
- Generate a mapping of tags->callbacks on parser init once and cache mapping as class attribute (avoid parent class lookups) - Performance: look up tags in cached mapping in `parse_line()` - Re-order `parse_tag_...` methods by definition order of RFC 8216 - Add docstring to each `parse_tag_...` method with link to RFC 8216 - Add typing annotations to each `parse_tag_...` method - Fix minor typing issues in regards to optional URIs in Key and Media and update parse methods accordingly - Pass keywords to various named tuples instead of positional args
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
and cache mapping as class attribute (avoid parent class lookups)
parse_line()parse_tag_...methods by definition order of RFC 8216parse_tag_...method with link to RFC 8216parse_tag_...methodand update parse methods accordingly
This improves the performance of the
M3U8Parser, as it doesn't have to generate a string with the name of supported tag methods for each tag anymore, and it can simply look up tags in a pre-generated mapping of tags->callbacks that get only built once after the first instantiation of the class. This is fully compatible withM3U8Parsersubclasses which override or add tag methods, and nothing has to be changed by those subclasses (tag method names stay the same). Subclasses have their own cache.One thing to note is that the parser doesn't call
tag.lower()anymore inparse_line(), which means that if for some reason an HLS playlist includes lowercase tag names or anything that doesn't match the exact case of the tag names, those invalid tags won't be recognized anymore, because tags are case sensitive.These changes will introduce a merge conflict with #4538.