[FFmpeg-devel,3/3] avformat/mpegts: use av_unlikely for detecting unknown streams

Submitted by Marton Balint on Jan. 24, 2019, 8:38 p.m.

Details

Message ID 20190124203801.18484-3-cus@passwd.hu
State New
Headers show

Commit Message

Marton Balint Jan. 24, 2019, 8:38 p.m.
Strangely the previous commit caused a slowdown in overall performance and
this fixes it. I used gcc 7.3.1. Does anybody else see this?

time ffprobe -show_packets samples/ffmpeg-bugs/trac/ticket6132/Samsung_HDR_-_Chasing_the_Light.ts > /dev/null

Before:
real    0m2,010s
user    0m1,413s
sys     0m0,596s

After:
real    0m1,948s
user    0m1,355s
sys     0m0,592s

Signed-off-by: Marton Balint <cus@passwd.hu>
---
 libavformat/mpegts.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Carl Eugen Hoyos Jan. 25, 2019, 12:16 a.m.
2019-01-24 21:38 GMT+01:00, Marton Balint <cus@passwd.hu>:
> Strangely the previous commit caused a slowdown in overall performance
> and this fixes it. I used gcc 7.3.1. Does anybody else see this?

No, but since this command exists nearly immediately for me
I see a 5% deviation even without your patch.

Carl Eugen
Marton Balint Jan. 25, 2019, 1:03 a.m.
On Fri, 25 Jan 2019, Carl Eugen Hoyos wrote:

> 2019-01-24 21:38 GMT+01:00, Marton Balint <cus@passwd.hu>:
>> Strangely the previous commit caused a slowdown in overall performance
>> and this fixes it. I used gcc 7.3.1. Does anybody else see this?
>
> No, but since this command exists nearly immediately for me
> I see a 5% deviation even without your patch.

Thanks for checking it. I tested my series on top of 
1b126ec4087ab5d87d413116bee666495b0d2d3e, and can still reproduce the 
speedup on it. On the other hand, on current git head, I can no longer 
reproduce the speedup. Whatever this is, the fact that using av_unlikely 
fixed it is probably just luck.

So considering the mixed feelings about av_(un)likely in general, I'll 
just drop patch 1 and 3.

Thanks,
Marton
Carl Eugen Hoyos Jan. 25, 2019, 1:09 a.m.
2019-01-25 2:03 GMT+01:00, Marton Balint <cus@passwd.hu>:
>
> On Fri, 25 Jan 2019, Carl Eugen Hoyos wrote:
>
>> 2019-01-24 21:38 GMT+01:00, Marton Balint <cus@passwd.hu>:
>>> Strangely the previous commit caused a slowdown in overall performance
>>> and this fixes it. I used gcc 7.3.1. Does anybody else see this?
>>
>> No, but since this command exists nearly immediately for me
>> I see a 5% deviation even without your patch.
>
> Thanks for checking it. I tested my series on top of
> 1b126ec4087ab5d87d413116bee666495b0d2d3e, and can still reproduce the
> speedup on it. On the other hand, on current git head, I can no longer
> reproduce the speedup. Whatever this is, the fact that using av_unlikely
> fixed it is probably just luck.
>
> So considering the mixed feelings about av_(un)likely in general, I'll
> just drop patch 1 and 3.

I would love to test a command line where it makes a (very) clear
difference, I wonder a little about the claim that it would help
(measurably) on some systems but not others.

Carl Eugen

Patch hide | download patch | download mbox

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index b04fd7b4f4..3003739b38 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -2477,7 +2477,7 @@  static int handle_packet(MpegTSContext *ts, const uint8_t *packet)
     pid = AV_RB16(packet + 1) & 0x1fff;
     is_start = packet[1] & 0x40;
     tss = ts->pids[pid];
-    if (ts->auto_guess && !tss && is_start) {
+    if (av_unlikely(ts->auto_guess && !tss && is_start)) {
         add_pes_stream(ts, pid, -1);
         tss = ts->pids[pid];
     }