Skip to content
This repository was archived by the owner on Dec 8, 2024. It is now read-only.

Conversation

bradleyfalzon
Copy link
Collaborator

@bradleyfalzon bradleyfalzon commented May 30, 2016

Alternative implementation of the improvements by @hori-ryota - all credits for actual changes is theirs.
This PR cherry picks the biggest impact but lowest risk and maintains ABI compatibility.

This is only an example PR, and will need verification, approval and rebasing before merging.

This branch:

Before:

BenchmarkDecodeMasterPlaylist-4   100000             22425 ns/op           12195 B/op         77 allocs/op
BenchmarkDecodeMediaPlaylist-4        50          23947209 ns/op        12279896 B/op     160059 allocs/op
BenchmarkEncodeMasterPlaylist-4  1000000              1023 ns/op              40 B/op         11 allocs/op
BenchmarkEncodeMediaPlaylist-4       100          12931950 ns/op         1748991 B/op      81607 allocs/op

After:

BenchmarkDecodeMasterPlaylist-4   100000             22534 ns/op           12194 B/op         77 allocs/op
BenchmarkDecodeMediaPlaylist-4       100          16132527 ns/op        10999880 B/op     120059 allocs/op
BenchmarkEncodeMasterPlaylist-4  1000000              1016 ns/op              40 B/op         11 allocs/op
BenchmarkEncodeMediaPlaylist-4       300           4471880 ns/op           45421 B/op        405 allocs/op

Benchstat Summary:

name                    old time/op    new time/op    delta
DecodeMasterPlaylist-4    22.4µs ± 0%    22.5µs ± 0%   ~             (p=1.000 n=1+1)
DecodeMediaPlaylist-4     23.9ms ± 0%    16.1ms ± 0%   ~             (p=1.000 n=1+1)
EncodeMasterPlaylist-4    1.02µs ± 0%    1.02µs ± 0%   ~             (p=1.000 n=1+1)
EncodeMediaPlaylist-4     12.9ms ± 0%     4.5ms ± 0%   ~             (p=1.000 n=1+1)

name                    old alloc/op   new alloc/op   delta
DecodeMasterPlaylist-4    12.2kB ± 0%    12.2kB ± 0%   ~             (p=1.000 n=1+1)
DecodeMediaPlaylist-4     12.3MB ± 0%    11.0MB ± 0%   ~             (p=1.000 n=1+1)
EncodeMasterPlaylist-4     40.0B ± 0%     40.0B ± 0%   ~     (all samples are equal)
EncodeMediaPlaylist-4     1.75MB ± 0%    0.05MB ± 0%   ~             (p=1.000 n=1+1)

name                    old allocs/op  new allocs/op  delta
DecodeMasterPlaylist-4      77.0 ± 0%      77.0 ± 0%   ~     (all samples are equal)
DecodeMediaPlaylist-4       160k ± 0%      120k ± 0%   ~             (p=1.000 n=1+1)
EncodeMasterPlaylist-4      11.0 ± 0%      11.0 ± 0%   ~     (all samples are equal)
EncodeMediaPlaylist-4      81.6k ± 0%      0.4k ± 0%   ~             (p=1.000 n=1+1)

https://github.com/hori-ryota/m3u8 - feature/improve-perform-decodeplaylist

Before:

BenchmarkDecodeMasterPlaylist-4   100000             23203 ns/op           14955 B/op         77 allocs/op
BenchmarkDecodeMediaPlaylist-4        50          24187010 ns/op        12279952 B/op     160060 allocs/op
BenchmarkEncodeMediaPlaylist-4       100          12919057 ns/op         1748992 B/op      81607 allocs/op

After:

BenchmarkDecodeMasterPlaylist-4   200000             10104 ns/op           12240 B/op         35 allocs/op
BenchmarkDecodeMediaPlaylist-4       100          16193330 ns/op         9200522 B/op      80019 allocs/op
BenchmarkEncodeMediaPlaylist-4       500           3697907 ns/op           21128 B/op        163 allocs/op

Benchstat Summary:

name                    old time/op    new time/op    delta
DecodeMasterPlaylist-4    23.2µs ± 0%    10.1µs ± 0%   ~     (p=1.000 n=1+1)
DecodeMediaPlaylist-4     24.2ms ± 0%    16.2ms ± 0%   ~     (p=1.000 n=1+1)
EncodeMediaPlaylist-4     12.9ms ± 0%     3.7ms ± 0%   ~     (p=1.000 n=1+1)

name                    old alloc/op   new alloc/op   delta
DecodeMasterPlaylist-4    15.0kB ± 0%    12.2kB ± 0%   ~     (p=1.000 n=1+1)
DecodeMediaPlaylist-4     12.3MB ± 0%     9.2MB ± 0%   ~     (p=1.000 n=1+1)
EncodeMediaPlaylist-4     1.75MB ± 0%    0.02MB ± 0%   ~     (p=1.000 n=1+1)

name                    old allocs/op  new allocs/op  delta
DecodeMasterPlaylist-4      77.0 ± 0%      35.0 ± 0%   ~     (p=1.000 n=1+1)
DecodeMediaPlaylist-4       160k ± 0%       80k ± 0%   ~     (p=1.000 n=1+1)
EncodeMediaPlaylist-4      81.6k ± 0%      0.2k ± 0%   ~     (p=1.000 n=1+1)

Before:
BenchmarkDecodeMasterPlaylist-4   100000             22425 ns/op           12195 B/op         77 allocs/op
BenchmarkDecodeMediaPlaylist-4        50          23947209 ns/op        12279896 B/op     160059 allocs/op
BenchmarkEncodeMasterPlaylist-4  1000000              1023 ns/op              40 B/op         11 allocs/op
BenchmarkEncodeMediaPlaylist-4       100          12931950 ns/op         1748991 B/op      81607 allocs/op

After:
BenchmarkDecodeMasterPlaylist-4   100000             22472 ns/op           12194 B/op         77 allocs/op
BenchmarkDecodeMediaPlaylist-4       100          21241158 ns/op        12279906 B/op     160060 allocs/op
BenchmarkEncodeMasterPlaylist-4  1000000              1025 ns/op              40 B/op         11 allocs/op
BenchmarkEncodeMediaPlaylist-4       100          13022881 ns/op         1748992 B/op      81607 allocs/op
Before:
BenchmarkDecodeMasterPlaylist-4   100000             22455 ns/op           12194 B/op         77 allocs/op
BenchmarkDecodeMediaPlaylist-4       100          21485138 ns/op        12279915 B/op     160061 allocs/op
BenchmarkEncodeMasterPlaylist-4  1000000              1025 ns/op              40 B/op         11 allocs/op
BenchmarkEncodeMediaPlaylist-4       100          13109618 ns/op         1748991 B/op      81607 allocs/op

After:
BenchmarkDecodeMasterPlaylist-4    50000             22486 ns/op           12194 B/op         77 allocs/op
BenchmarkDecodeMediaPlaylist-4       100          17205525 ns/op        10999878 B/op     120060 allocs/op
BenchmarkEncodeMasterPlaylist-4  1000000              1016 ns/op              40 B/op         11 allocs/op
BenchmarkEncodeMediaPlaylist-4       100          13020206 ns/op         1736192 B/op      81207 allocs/op
Before:
BenchmarkDecodeMasterPlaylist-4   100000             22461 ns/op           12194 B/op         77 allocs/op
BenchmarkDecodeMediaPlaylist-4       100          16692449 ns/op        10999880 B/op     120059 allocs/op
BenchmarkEncodeMasterPlaylist-4  1000000              1025 ns/op              40 B/op         11 allocs/op
BenchmarkEncodeMediaPlaylist-4       100          13014814 ns/op         1736192 B/op      81207 allocs/op

After:
BenchmarkDecodeMasterPlaylist-4   100000             22482 ns/op           12194 B/op         77 allocs/op
BenchmarkDecodeMediaPlaylist-4       100          15918199 ns/op        10999881 B/op     120060 allocs/op
BenchmarkEncodeMasterPlaylist-4  1000000              1058 ns/op              40 B/op         11 allocs/op
BenchmarkEncodeMediaPlaylist-4       100          12738933 ns/op         1736192 B/op      81207 allocs/op
Note, this uses a map as a cache, and does not limit its size and therefore
could become very large. If this occurs, there's another option which
only caches the last result, but assumes all durations are identical, which
isn't always true. But does provide equivalent speed improvements when
the durations are identical and doesn't involve a map (just two local variables).

Before:
BenchmarkDecodeMasterPlaylist-4   100000             22543 ns/op           12194 B/op         77 allocs/op
BenchmarkDecodeMediaPlaylist-4       100          16008868 ns/op        10999875 B/op     120059 allocs/op
BenchmarkEncodeMasterPlaylist-4  1000000              1020 ns/op              40 B/op         11 allocs/op
BenchmarkEncodeMediaPlaylist-4       100          12914307 ns/op         1736190 B/op      81207 allocs/op

After:
BenchmarkDecodeMasterPlaylist-4   100000             22534 ns/op           12194 B/op         77 allocs/op
BenchmarkDecodeMediaPlaylist-4       100          16132527 ns/op        10999880 B/op     120059 allocs/op
BenchmarkEncodeMasterPlaylist-4  1000000              1016 ns/op              40 B/op         11 allocs/op
BenchmarkEncodeMediaPlaylist-4       300           4471880 ns/op           45421 B/op        405 allocs/op
@bradleyfalzon bradleyfalzon merged commit d61d587 into grafov:master Jun 6, 2016
@grafov grafov removed the in progress label Jun 6, 2016
@bradleyfalzon bradleyfalzon deleted the hori-improvements branch June 6, 2016 01:18
grafov pushed a commit that referenced this pull request Nov 22, 2016
Hori improvements - Alternative approach
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants