From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <ffmpeg-devel-bounces@ffmpeg.org>
Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100])
	by master.gitmailbox.com (Postfix) with ESMTPS id AFCF54CDD6
	for <ffmpegdev@gitmailbox.com>; Mon, 14 Apr 2025 11:33:41 +0000 (UTC)
Received: from [127.0.1.1] (localhost [127.0.0.1])
	by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id ABACB687C71;
	Mon, 14 Apr 2025 14:33:36 +0300 (EEST)
Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net
 [217.70.183.196])
 by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5D034687C2A
 for <ffmpeg-devel@ffmpeg.org>; Mon, 14 Apr 2025 14:33:30 +0300 (EEST)
Received: by mail.gandi.net (Postfix) with ESMTPSA id 8E2F543AE8
 for <ffmpeg-devel@ffmpeg.org>; Mon, 14 Apr 2025 11:33:29 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=niedermayer.cc;
 s=gm1; t=1744630409;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:mime-version:mime-version:content-type:content-type;
 bh=4ve7N3cQR/HQNxVXr+JqHDTq63y1a2ZVkFYOXLkXNTA=;
 b=CysJtObrcM9NQhSTXRtKh1HIpBPHd7m0ks0UiC5Y3Qd/OmROuMAOe5b0EesVL8QH0Vb214
 sBsrFoFnnhNxuPMiCOlcW+Z2CM+cDUXNe2LfLZwA53uc8jnFzY7RYFW4iNYTIaNNkuPt3E
 yL9hWJMLvA9EZvIfRW4efTwX4XS+5wbbHVkxjQmnsQHcvMtB4JpIHs/R/RUnHy+1+ErhBZ
 4drgStsFRw0kZMZVAn69NcKsE6569M5xy3EL6zuqecc6BuqjalQzU9vmZFBYuAqzl6/3Jv
 dklgjncR+BK8bK/g97qRtPZkNElSnXufUbsnhLAIo8B0ZT2lEIAwL2Vi1eqlfA==
Date: Mon, 14 Apr 2025 13:33:28 +0200
From: Michael Niedermayer <michael@niedermayer.cc>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Message-ID: <20250414113328.GM4991@pb2>
MIME-Version: 1.0
X-GND-State: clean
X-GND-Score: -70
X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvvddtgeehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfghrlhcuvffnffculdeftddmnecujfgurhepfffhvffukfggtggusehgtderredttddvnecuhfhrohhmpefoihgthhgrvghlucfpihgvuggvrhhmrgihvghruceomhhitghhrggvlhesnhhivgguvghrmhgrhigvrhdrtggtqeenucggtffrrghtthgvrhhnpeeifeegvefgvdegledugeehlefhgeffvdeggfdtgeevgeduleevieeuleeiteevffenucfkphepgedurdeiiedrieejrdduudefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepgedurdeiiedrieejrdduudefpdhhvghloheplhhotggrlhhhohhsthdpmhgrihhlfhhrohhmpehmihgthhgrvghlsehnihgvuggvrhhmrgihvghrrdgttgdpnhgspghrtghpthhtohepuddprhgtphhtthhopehffhhmphgvghdquggvvhgvlhesfhhfmhhpvghgrdhorhhg
X-GND-Sasl: michael@niedermayer.cc
Subject: [FFmpeg-devel] AVDictionary vs. AVSet (AVDictionary2 approximation)
X-BeenThere: ffmpeg-devel@ffmpeg.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org>
List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe>
List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel>
List-Post: <mailto:ffmpeg-devel@ffmpeg.org>
List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help>
List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe>
Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Content-Type: multipart/mixed; boundary="===============6207790286673397722=="
Errors-To: ffmpeg-devel-bounces@ffmpeg.org
Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org>
Archived-At: <https://master.gitmailbox.com/ffmpegdev/20250414113328.GM4991@pb2/>
List-Archive: <https://master.gitmailbox.com/ffmpegdev/>
List-Post: <mailto:ffmpegdev@gitmailbox.com>


--===============6207790286673397722==
Content-Type: multipart/signed; micalg=pgp-sha512;
	protocol="application/pgp-signature"; boundary="sYBntiLGrZ+ncVCX"
Content-Disposition: inline


--sYBntiLGrZ+ncVCX
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Hi

I just posted a AVSet implementation i wrote in the last 2 days (yes thats
why i did dissapear for the last 2 days)

My plan was to use that AVSet as basis for AVDictionary2 in case
benchmarks indicate that its worth it, so is it ?

with 3 entries (100000 runs)
AVDictionary    0.040sec
AVSet           0.027sec

with 5 entries (100000 runs)
AVDictionary    0.065sec
AVSet           0.042sec

with 10 entries (100000 runs)
AVDictionary    0.193sec
AVSet           0.087sec

with 100 entries (100000 runs)
AVDictionary    8.7  sec
AVSet           1.4  sec

with 1000 entries (1000 runs)
AVDictionary    8.0   sec
AVSet           0.240 sec

with 10000 entries (10 runs)
AVDictionary    7.2   sec
AVSet           0.042 sec


I was a bit surprised for the 3 and 5 entry case, maybe my benchmark is bug=
gy or
AVSet is, but then AVDictionary is pretty bad with memory allocations

AVDictionary needs to strdup every key and value, needs to allocate
the AVDictionary itself and reallocs the entry array each time
thats 10 memory allocation related calls for adding 3 entries

while AVSet allocates the AVSet and then uses av_fast_realloc() for the arr=
ay
and theres nothing else, the key/value goes in that array too


bechmark code used is below:


#if 0
    for (int runs =3D 0; runs < 100000; runs++) {
        AVSet *set =3D av_set_new(strcmp, NULL, NULL);
        for(int pass =3D 0; pass < 2; pass++) {
            unsigned r =3D 5;
            for(int i=3D0; i<100; i++) {
                r =3D r*123 + 7;
                char str[2*7] =3D "TESTXXTESTXX";
                str[4] =3D r;
                str[5] =3D r>>8;
                if(pass =3D=3D 0) {
                    av_set_add(set, str, 2*7, 0);
                } else {
                    av_set_get(set, NULL, str, NULL);
                }
            }
        }
        av_set_free(&set);
    }
#else
    for (int runs =3D 0; runs < 100000; runs++) {
        AVDictionary *dict =3D NULL;
        for(int pass =3D 0; pass < 2; pass++) {
            unsigned r =3D 5;
            for(int i=3D0; i<100; i++) {
                r =3D r*123 + 7;
                char str[7] =3D "TEST";
                str[4] =3D r;
                str[5] =3D r>>8;
                if(pass =3D=3D 0) {
                    av_dict_set(&dict, str, str, 0);
                } else {
                    av_dict_get(dict, str, NULL, 0);
                }
            }
        }
        av_dict_free(&dict);
    }
#endif


--=20
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Good people do not need laws to tell them to act responsibly, while bad
people will find a way around the laws. -- Plato

--sYBntiLGrZ+ncVCX
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iF0EABEKAB0WIQSf8hKLFH72cwut8TNhHseHBAsPqwUCZ/zyhQAKCRBhHseHBAsP
q8jtAJ0RKa9pxeV4o5G8eAs+kg2HKaBegQCfRFt85nUaWMTt0wgeJ62FU0s3tcc=
=ibJi
-----END PGP SIGNATURE-----

--sYBntiLGrZ+ncVCX--

--===============6207790286673397722==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
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".

--===============6207790286673397722==--