-
Notifications
You must be signed in to change notification settings - Fork 320
Add (seg MediaSegment)String() #100
base: master
Are you sure you want to change the base?
Conversation
I'm concerned that we'd now have two different methods to write a segment. Can we not move the following to an unexported function, which takes a https://github.com/grafov/m3u8/blob/master/writer.go#L483-L600 As long as performance isn't drastically affected. |
@bradleyfalzon |
Thanks @keizo042 that change is better, but there's still some duplication of the if statements. We've created a few new unexported functions, which is good, but I'd think there should just be one function that both Unless there's a specific reason we can't do that? |
I agree but there is two difference. In addition, so it needs I feel need to create unexported function as rest part of writing media segment in order to remove duplicated code. |
Ah yes, I see. This is unfortunate.
Yeah, so this is so for very large playlists, we don't continue to call the intensive I then understand why you've chosen this method, but I do prefer if we could remove the duplication completely. I don't mind duplicate code, but there's a lot of logic here that's being duplicated and that's what concerns me. What if there was a function like // writeSegment writes a string representation of seg to buf.
//
// durationCache is required to reduce the number of calls to repetitive strconv formats.
// If playlist is non-nil, additional context is derived from the playlist.
func writeSegment(seg MediaSegment, buf bytes.Buffer, durationCache map[float]string, playlist *MediaPlaylist, buf bytes.Buffer) Then the same if statements that used information from the playlist would first check if playlist is non-nil. -if p.Map == nil && seg.Map != nil {
+if p != nil && p.Map == nil && seg.Map != nil { Or similar? I'm not 100% for my suggestion, just asking your thoughts. |
That's good idea. func (seg MediaSegment) write(buf bytes.Buffer, p *MediaPlaylist, durationCache map[string]float
) {
...
if p != nil {
if p.Map == nil && seg.Map != nil {
writeMap(buf, seg.Map)
}
} else {
writeMap(buf, seg.Map)
}
...
if p != nil {
// original caching and conversion
} else {
buf.WriteString(strconv.FormatFloat(seg.Duration, 'f', 3, 32))
}
...
} |
This is looking good to me I think. Could you run the benchmarks before and after to check for performance regressions? |
benchmark resutls Env
result
only Encode MediaPlaylist benchmark
well... I think we prefer that peformance regression is under 0.1sec. |
related #98