diff mbox series

[FFmpeg-devel,10/21] avcodec/smacker: Use better nb_codes estimate when initializing VLC

Message ID 20200801134704.3647-2-andreas.rheinhardt@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/8] avcodec/smacker: Remove write-only and unused variables
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Aug. 1, 2020, 1:46 p.m. UTC
Using the real number of read codes allows to leave a loop in
ff_init_vlc_sparse earlier; notice that all codes not explicitly
set by reading data have been set to zero earlier (i.e. they are
zero-length codes) and such codes are ignored by ff_init_vlc_sparse.

This improves performance: When compiled with GCC 9, the time spent on
one call to smka_decode_frame() for the sample from ticket #2425
decreased from 2195367 decicycles to 2068389 decicycles. For Clang 9,
it improved from 1602075 to 1534188 decicycles. These tests have been
performed 20 times and each times the input file has been looped
32 times to get a sufficient number of frames.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/smacker.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Paul B Mahol Aug. 1, 2020, 1:58 p.m. UTC | #1
probably ok

On 8/1/20, Andreas Rheinhardt <andreas.rheinhardt@gmail.com> wrote:
> Using the real number of read codes allows to leave a loop in
> ff_init_vlc_sparse earlier; notice that all codes not explicitly
> set by reading data have been set to zero earlier (i.e. they are
> zero-length codes) and such codes are ignored by ff_init_vlc_sparse.
>
> This improves performance: When compiled with GCC 9, the time spent on
> one call to smka_decode_frame() for the sample from ticket #2425
> decreased from 2195367 decicycles to 2068389 decicycles. For Clang 9,
> it improved from 1602075 to 1534188 decicycles. These tests have been
> performed 20 times and each times the input file has been looped
> 32 times to get a sufficient number of frames.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavcodec/smacker.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/libavcodec/smacker.c b/libavcodec/smacker.c
> index e6b163722a..27de30f0e1 100644
> --- a/libavcodec/smacker.c
> +++ b/libavcodec/smacker.c
> @@ -214,7 +214,7 @@ static int smacker_decode_header_tree(SmackVContext
> *smk, GetBitContext *gb, int
>              goto error;
>          skip_bits1(gb);
>          if (h[i].current > 1) {
> -            err = init_vlc(&vlc[i], SMKTREE_BITS, h[i].length,
> +            err = init_vlc(&vlc[i], SMKTREE_BITS, h[i].current,
>                             INIT_VLC_DEFAULT_SIZES(h[i].lengths),
>                             INIT_VLC_DEFAULT_SIZES(h[i].bits),
>                             INIT_VLC_LE);
> @@ -657,7 +657,7 @@ static int smka_decode_frame(AVCodecContext *avctx, void
> *data,
>              goto error;
>          skip_bits1(&gb);
>          if(h[i].current > 1) {
> -            ret = init_vlc(&vlc[i], SMKTREE_BITS, h[i].length,
> +            ret = init_vlc(&vlc[i], SMKTREE_BITS, h[i].current,
>                      h[i].lengths, sizeof(int), sizeof(int),
>                      h[i].bits, sizeof(uint32_t), sizeof(uint32_t),
> INIT_VLC_LE);
>              if (ret < 0) {
> --
> 2.20.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/libavcodec/smacker.c b/libavcodec/smacker.c
index e6b163722a..27de30f0e1 100644
--- a/libavcodec/smacker.c
+++ b/libavcodec/smacker.c
@@ -214,7 +214,7 @@  static int smacker_decode_header_tree(SmackVContext *smk, GetBitContext *gb, int
             goto error;
         skip_bits1(gb);
         if (h[i].current > 1) {
-            err = init_vlc(&vlc[i], SMKTREE_BITS, h[i].length,
+            err = init_vlc(&vlc[i], SMKTREE_BITS, h[i].current,
                            INIT_VLC_DEFAULT_SIZES(h[i].lengths),
                            INIT_VLC_DEFAULT_SIZES(h[i].bits),
                            INIT_VLC_LE);
@@ -657,7 +657,7 @@  static int smka_decode_frame(AVCodecContext *avctx, void *data,
             goto error;
         skip_bits1(&gb);
         if(h[i].current > 1) {
-            ret = init_vlc(&vlc[i], SMKTREE_BITS, h[i].length,
+            ret = init_vlc(&vlc[i], SMKTREE_BITS, h[i].current,
                     h[i].lengths, sizeof(int), sizeof(int),
                     h[i].bits, sizeof(uint32_t), sizeof(uint32_t), INIT_VLC_LE);
             if (ret < 0) {