Opened 11 years ago

Closed 11 years ago

#2839 closed defect (needs_more_info)

Wasted work in av_new_program() and avpriv_new_chapter()

Reported by: Po-Chun Chang Owned by:
Priority: normal Component: avformat
Version: unspecified Keywords: performance
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

The problem appears in latest revision. I have attached a simple one-line patch that fixes it.

In method av_new_program() in libavformat/utils.c, the loop in line 3431 keeps overriding "program" with "ac->programs[i]" when its "id" equals to "id" Therefore, only the last written value is visible out of the loop and all the other writes and iterations are not necessary. The patch iterates from the end of "i" and breaks the first time when "program" is set.

Similar problem also appears in avpriv_new_chapter(), the loop in line 3457. The patch iterates from the end of "i" and breaks the first time when "chapter" is set.

Attachments (2)

patch1.diff (563 bytes ) - added by Po-Chun Chang 11 years ago.
Suggested patch part 1
patch2.diff (549 bytes ) - added by Po-Chun Chang 11 years ago.
Suggested patch part 2

Download all attachments as: .zip

Change History (4)

by Po-Chun Chang, 11 years ago

Attachment: patch1.diff added

Suggested patch part 1

by Po-Chun Chang, 11 years ago

Attachment: patch2.diff added

Suggested patch part 2

comment:1 by Michael Niedermayer, 11 years ago

Component: undeterminedavformat

using a ts stream the old loop in av_new_program() executes in 50 cpu cycles, the new after the patch in 77 cycles.
in 30 seconds the code gets about 1000 times executed in my test file which makes this loop take 0.00008% of the execution time.
Thus this code does not appear to be performance relevant and your change makes it slower. At least for the testcase i used.
also please always test performance improvment suggestions and include the test results in the ticket.
Do you have a testcase for these 2 patches that shows a improvment ?

comment:2 by Elon Musk, 11 years ago

Resolution: needs_more_info
Status: newclosed
Note: See TracTickets for help on using tickets.