linux/scripts/kconfig
Masahiro Yamada f93d6bfbd2 kconfig: use hash table to reuse expressions
Currently, every expression in Kconfig files produces a new abstract
syntax tree (AST), even if it is identical to a previously encountered
one.

Consider the following code:

    config FOO
           bool "FOO"
           depends on (A || B) && C

    config BAR
           bool "BAR"
           depends on (A || B) && C

    config BAZ
           bool "BAZ"
           depends on A || B

The "depends on" lines are similar, but currently a separate AST is
allocated for each one.

The current data structure looks like this:

  FOO->dep ==> AND        BAR->dep ==> AND        BAZ->dep ==> OR
              /   \                   /   \                   /  \
            OR     C                OR     C                 A    B
           /  \                    /  \
          A    B                  A    B

This is redundant; FOO->dep and BAR->dep have identical ASTs but
different memory instances.

We can optimize this; FOO->dep and BAR->dep can share the same AST, and
BAZ->dep can reference its sub tree.

The optimized data structure looks like this:

  FOO->dep, BAR->dep ==> AND
                        /   \
         BAZ->dep ==> OR     C
                     /  \
                    A    B

This commit introduces a hash table to keep track of allocated
expressions. If an identical expression is found, it is reused.

This does not necessarily result in memory savings, as menu_finalize()
transforms expressions without freeing up stale ones. This will be
addressed later.

One optimization that can be easily implemented is caching the
expression's value. Once FOO's dependency, (A || B) && C, is calculated,
it can be cached, eliminating the need to recalculate it for BAR.

This commit also reverts commit e983b7b17a ("kconfig/menu.c: fix
multiple references to expressions in menu_add_prop()").

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-09-20 09:21:52 +09:00
..
lxdialog kconfig: lxdialog: remove initialization with A_NORMAL 2024-05-14 23:36:19 +09:00
tests kconfig: recursive checks drop file/lineno 2024-07-20 16:33:45 +09:00
.gitignore kconfig: Update all declared targets 2023-01-13 16:29:52 +09:00
conf.c kconfig: remove sym_get_choice_value() 2024-07-16 01:08:37 +09:00
confdata.c kbuild: split x*alloc() functions in kconfig to scripts/include/xalloc.h 2024-09-01 20:34:48 +09:00
expr.c kconfig: use hash table to reuse expressions 2024-09-20 09:21:52 +09:00
expr.h kconfig: use hash table to reuse expressions 2024-09-20 09:21:52 +09:00
gconf-cfg.sh kconfig: add -e and -u options to *conf-cfg.sh scripts 2024-07-16 01:08:36 +09:00
gconf.c kconfig: remove SYMBOL_CHOICEVAL flag 2024-07-16 16:07:14 +09:00
gconf.glade
images.c
images.h
internal.h kconfig: use hash table to reuse expressions 2024-09-20 09:21:52 +09:00
lexer.l kbuild: split x*alloc() functions in kconfig to scripts/include/xalloc.h 2024-09-01 20:34:48 +09:00
lkc_proto.h kconfig: add const qualifiers to several function arguments 2024-07-16 16:07:14 +09:00
lkc.h scripts: move hash function from scripts/kconfig/ to scripts/include/ 2024-09-20 09:21:52 +09:00
Makefile kbuild: use $(src) instead of $(srctree)/$(src) for source directory 2024-05-10 04:34:52 +09:00
mconf-cfg.sh kconfig: add -e and -u options to *conf-cfg.sh scripts 2024-07-16 01:08:36 +09:00
mconf.c kbuild: split x*alloc() functions in kconfig to scripts/include/xalloc.h 2024-09-01 20:34:48 +09:00
menu.c kconfig: use hash table to reuse expressions 2024-09-20 09:21:52 +09:00
merge_config.sh scripts: kconfig: merge_config: config files: add a trailing newline 2024-08-06 14:02:12 +09:00
mnconf-common.c kbuild: move some helper headers from scripts/kconfig/ to scripts/include/ 2024-07-21 23:10:43 +09:00
mnconf-common.h kbuild: move some helper headers from scripts/kconfig/ to scripts/include/ 2024-07-21 23:10:43 +09:00
nconf-cfg.sh kconfig: add -e and -u options to *conf-cfg.sh scripts 2024-07-16 01:08:36 +09:00
nconf.c kbuild: split x*alloc() functions in kconfig to scripts/include/xalloc.h 2024-09-01 20:34:48 +09:00
nconf.gui.c kbuild: split x*alloc() functions in kconfig to scripts/include/xalloc.h 2024-09-01 20:34:48 +09:00
nconf.h kconfig: nconf: Add search jump feature 2023-08-13 21:29:41 +09:00
parser.y kbuild: split x*alloc() functions in kconfig to scripts/include/xalloc.h 2024-09-01 20:34:48 +09:00
preprocess.c kbuild: split x*alloc() functions in kconfig to scripts/include/xalloc.h 2024-09-01 20:34:48 +09:00
preprocess.h kconfig: split preprocessor prototypes into preprocess.h 2024-02-19 18:20:40 +09:00
qconf-cfg.sh kconfig: add -e and -u options to *conf-cfg.sh scripts 2024-07-16 01:08:36 +09:00
qconf.cc kbuild: split x*alloc() functions in kconfig to scripts/include/xalloc.h 2024-09-01 20:34:48 +09:00
qconf.h kconfig: pass new conf_changed value to the callback 2024-07-16 01:08:36 +09:00
streamline_config.pl streamline_config.pl: handle also ${CONFIG_FOO} 2023-06-08 11:11:32 +09:00
symbol.c scripts: move hash function from scripts/kconfig/ to scripts/include/ 2024-09-20 09:21:52 +09:00
util.c scripts: move hash function from scripts/kconfig/ to scripts/include/ 2024-09-20 09:21:52 +09:00