[FFmpeg-devel] Optimize libavformat/metadata.c

Submitted by Shlomi Fish on July 4, 2018, 8:10 p.m.

Details

Message ID 20180704231046.1fe7845a@telaviv1.shlomifish.org
State New
Headers show

Commit Message

Shlomi Fish July 4, 2018, 8:10 p.m.

Comments

Shlomi Fish July 11, 2018, 4:42 p.m.
On Wed, 4 Jul 2018 23:10:46 +0300
Shlomi Fish <shlomif@shlomifish.org> wrote:

Ping! Can this patch be reviewed please?
Shlomi Fish July 20, 2018, 11:31 a.m.
On Wed, 11 Jul 2018 19:42:09 +0300
Shlomi Fish <shlomif@shlomifish.org> wrote:

> On Wed, 4 Jul 2018 23:10:46 +0300
> Shlomi Fish <shlomif@shlomifish.org> wrote:
> 
> Ping! Can this patch be reviewed please?
> 

Ping!

>
Shlomi Fish Aug. 23, 2018, 5:37 p.m.
On Fri, 20 Jul 2018 14:31:55 +0300
Shlomi Fish <shlomif@shlomifish.org> wrote:

> On Wed, 11 Jul 2018 19:42:09 +0300
> Shlomi Fish <shlomif@shlomifish.org> wrote:
> 
> > On Wed, 4 Jul 2018 23:10:46 +0300
> > Shlomi Fish <shlomif@shlomifish.org> wrote:
> > 
> > Ping! Can this patch be reviewed please?
> >   
> 
> Ping!

bump / ping.
Shlomi Fish Nov. 7, 2018, 9:21 a.m.
On Wed, 4 Jul 2018 23:10:46 +0300
Shlomi Fish <shlomif@shlomifish.org> wrote:

Ping/bump! Can this patch be reviewed already?
Marton Balint Nov. 7, 2018, 9:29 a.m.
On Wed, 7 Nov 2018, Shlomi Fish wrote:

> On Wed, 4 Jul 2018 23:10:46 +0300
> Shlomi Fish <shlomif@shlomifish.org> wrote:
>
> Ping/bump! Can this patch be reviewed already?

Does your patch has any measureable speed difference for some streams? It 
seems like a very micro optimialization, because ff_metadata_conv bails
out early as well.

Regards,
Marton
Shlomi Fish Nov. 15, 2018, 9:26 a.m.
Hi Marton,

On Wed, 7 Nov 2018 10:29:31 +0100 (CET)
Marton Balint <cus@passwd.hu> wrote:

> On Wed, 7 Nov 2018, Shlomi Fish wrote:
> 
> > On Wed, 4 Jul 2018 23:10:46 +0300
> > Shlomi Fish <shlomif@shlomifish.org> wrote:
> >
> > Ping/bump! Can this patch be reviewed already?  
> 
> Does your patch has any measureable speed difference for some streams? It 
> seems like a very micro optimialization, because ff_metadata_conv bails
> out early as well.
>

First of all note that I recall it being the case for several function calls
in succession there. Secondly, I didn't measure it, but see what I wrote at:

https://en.wikibooks.org/wiki/Optimizing_Code_for_Speed/Factor_Optimizations#Are_%22Small%22_Optimizations_Desirable?

non-inline function calls can be quite slow.  

> Regards,
> Marton
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Hendrik Leppkes Nov. 15, 2018, 9:35 a.m.
On Thu, Nov 15, 2018 at 10:27 AM Shlomi Fish <shlomif@shlomifish.org> wrote:
>
> Hi Marton,
>
> On Wed, 7 Nov 2018 10:29:31 +0100 (CET)
> Marton Balint <cus@passwd.hu> wrote:
>
> > On Wed, 7 Nov 2018, Shlomi Fish wrote:
> >
> > > On Wed, 4 Jul 2018 23:10:46 +0300
> > > Shlomi Fish <shlomif@shlomifish.org> wrote:
> > >
> > > Ping/bump! Can this patch be reviewed already?
> >
> > Does your patch has any measureable speed difference for some streams? It
> > seems like a very micro optimialization, because ff_metadata_conv bails
> > out early as well.
> >
>
> First of all note that I recall it being the case for several function calls
> in succession there. Secondly, I didn't measure it, but see what I wrote at:
>
> https://en.wikibooks.org/wiki/Optimizing_Code_for_Speed/Factor_Optimizations#Are_%22Small%22_Optimizations_Desirable?
>
> non-inline function calls can be quite slow.
>

Theoretical optimizations are all nice and well, but numbers are the
only reality in the world. :)

- Hendrik

Patch hide | download patch | download mbox

From 98e0629d28394f8683abd98f80645ee63b295d24 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Wed, 4 Jul 2018 22:53:08 +0300
Subject: [PATCH] Short-circuit several calls on a condition.

This is an optimization - more details in the comment in the changeset.
---
 libavformat/metadata.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libavformat/metadata.c b/libavformat/metadata.c
index b9b6de7972..4b720efd38 100644
--- a/libavformat/metadata.c
+++ b/libavformat/metadata.c
@@ -60,6 +60,10 @@  void ff_metadata_conv_ctx(AVFormatContext *ctx, const AVMetadataConv *d_conv,
                                                 const AVMetadataConv *s_conv)
 {
     int i;
+    /* We pass those to all ff_metadata_conv calls below and it returns
+     * immediately if they are equal, so we can short-circuit. */
+    if (d_conv == s_conv)
+        return;
     ff_metadata_conv(&ctx->metadata, d_conv, s_conv);
     for (i=0; i<ctx->nb_streams ; i++)
         ff_metadata_conv(&ctx->streams [i]->metadata, d_conv, s_conv);
-- 
2.18.0