Opened 6 years ago

Closed 6 years ago

#2839 closed defect (needs_more_info)

Wasted work in av_new_program() and avpriv_new_chapter()

Reported by: pchang9 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 pchang9 6 years ago.
Suggested patch part 1
patch2.diff (549 bytes) - added by pchang9 6 years ago.
Suggested patch part 2

Download all attachments as: .zip

Change History (4)

Changed 6 years ago by pchang9

Suggested patch part 1

Changed 6 years ago by pchang9

Suggested patch part 2

comment:1 Changed 6 years ago by michael

  • Component changed from undetermined to avformat

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 Changed 6 years ago by richardpl

  • Resolution set to needs_more_info
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.