[PATCH 1/5] lavf/mxfdec: Speed up klv_read_packet()
This patchset speeds up mxfdec in various ways. The test file has been generated with ffmpeg -t 10000 -f lavfi -i testsrc -s 160x120 out2.mxf Performance is measured with callgrind using the command valgrind --tool=callgrind ./ffmpeg_g -loglevel quiet -i out2.mxf -codec copy -f null - The callgraph has then been inspected using kcachegrind. The results are as follows: task_wrapper 5 812 306 937 a577d31 5 669 552 343 Speed up klv_read_packet() 5 648 440 947 Add and use IS_KLV_KEY_FAST() in some places 5 633 846 074 Add and use mxf_is_encrypted_triplet_key() 3 667 721 703 Speed up mxf_edit_unit_absolute_offset() 3 587 869 726 Remove a call to avio_tell() in klv_read_packet() mxf_read_packet (250 001 calls) 3 821 662 859 a577d31 3 665 058 265 Speed up klv_read_packet() 3 647 320 931 Add and use IS_KLV_KEY_FAST() in some places 3 624 081 036 Add and use mxf_is_encrypted_triplet_key() 1 660 495 552 Speed up mxf_edit_unit_absolute_offset() 1 592 469 709 Remove a call to avio_tell() in klv_read_packet() The biggest difference is made by speeding up mxf_edit_unit_absolute_offset(). Here's how many cycles it uses before and after patch 4: mxf_edit_unit_absolute_offset.constprop.31 2 076 774 255 Add and use mxf_is_encrypted_triplet_key() 105 047 878 Speed up mxf_edit_unit_absolute_offset() Of the remaining cycles in mxf_edit_unit_absolute_offset(), 67 882 294 are spent in mxf_absolute_bodysid_offset() (272 cycles per call). Since it already does a binary search it didn't seem worthwhile to mess with. Patches 2 and 3 are somewhat dubious, but I've included them anyway to get some feedback. We could both speed up the demuxer and cut down on .text by omitting the first 4 bytes of every key. /Tomas
This gives some gains, but would probably be nicer if it leveraged the type system by defining a specific type for 12-byte keys so there can be no accidental mixup /Tomas
mxf_match_uid() is rather slow and gets called a lot. Unrolling it like this saves some cycles, but probably not enough to justify making the code much more verbose /Tomas
On Sun, 22 Sep 2024, Tomas Härdin wrote:
mxf_match_uid() is rather slow and gets called a lot. Unrolling it like this saves some cycles, but probably not enough to justify making the code much more verbose
Yeah, this looks a bit overkill. Regards, Marton
This is the big one. The offset_temp calculations that used to be part of mxf_edit_unit_absolute_offset() are moved to mxf_compute_index_tables() and are done only once. This also makes random access in mxf_edit_unit_absolute_offset() possible /Tomas
I'll push patches 1, 4 and 5 in a few days. /Tomas
fre 2024-09-27 klockan 15:22 +0200 skrev Tomas Härdin:
I'll push patches 1, 4 and 5 in a few days.
Pushed /Tomas
participants (2)
-
Marton Balint -
Tomas Härdin