[vlc-devel] [PATCH] modules: use 16-bit ints for option counts
Alexandre Janniaux
ajanni at videolabs.io
Mon Sep 28 09:07:16 CEST 2020
Hi,
In addition to Rémi's argument, I'll add that saving 16 bytes
for a hundred plugins by adding more core to handle errors,
while we are usually allocating more frames than needed is a
micro optimization bringing complexity more than anything,
which is quite different from a «free» save of space.
Regards,
--
Alexandre Janniaux
Videolabs
On Sat, Sep 26, 2020 at 10:41:23PM +0100, Lyndon Brown wrote:
> attached. preview:
>
> From: Lyndon Brown <jnqnfe at gmail.com>
> Date: Wed, 10 Apr 2019 03:48:17 +0100
> Subject: modules: use 16-bit ints for option counts
>
> nothings is going to need more than UINT16_MAX options, let's be sensible
> and save the space. note, i may have instead used 8-bit ints, but that's
> way too small for the core set.
>
> added an assert on size when adding modules in entry.c to be safe though.
>
> on 64-bit this saves 16 bytes per plugin (of which there are typically
> hundreds). i.e. we cut the storage space for this plugin conf data to half
> of what it currently is.
>
> diff --git a/src/modules/entry.c b/src/modules/entry.c
> index fc7f3cdbb6..cb06085b9c 100644
> --- a/src/modules/entry.c
> +++ b/src/modules/entry.c
> @@ -142,6 +142,8 @@ static module_config_t *vlc_config_create(vlc_plugin_t *plugin, int type)
> unsigned confsize = plugin->conf.size;
> module_config_t *tab = plugin->conf.items;
>
> + assert(confsize < UINT16_MAX);
> +
> if ((confsize & 0xf) == 0)
> {
> tab = realloc_or_free (tab, (confsize + 17) * sizeof (*tab));
> diff --git a/src/modules/modules.h b/src/modules/modules.h
> index 93cc1ca289..752b138c84 100644
> --- a/src/modules/modules.h
> +++ b/src/modules/modules.h
> @@ -40,9 +40,9 @@ typedef struct vlc_plugin_t
> struct
> {
> module_config_t *items; /**< Table of configuration items */
> - size_t size; /**< Total count of all items */
> - size_t count; /**< Count of real options (excludes hints) */
> - size_t booleans; /**< Count of options that are of boolean type */
> + uint16_t size; /**< Total count of all items */
> + uint16_t count; /**< Count of real options (excludes hints) */
> + uint16_t booleans; /**< Count of options that are of boolean type */
> } conf;
>
> #ifdef HAVE_DYNAMIC_PLUGINS
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
More information about the vlc-devel
mailing list