<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux.git/scripts/include/hash.h, branch v6.18.21</title>
<subtitle>Clone of https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git</subtitle>
<link rel='alternate' type='text/html' href='https://git.exis.tech/linux.git/'/>
<entry>
<title>kconfig: use hash table to reuse expressions</title>
<updated>2024-09-20T00:21:52+00:00</updated>
<author>
<name>Masahiro Yamada</name>
<email>masahiroy@kernel.org</email>
</author>
<published>2024-09-08T12:43:20+00:00</published>
<link rel='alternate' type='text/html' href='https://git.exis.tech/linux.git/commit/?id=f93d6bfbd2f74d79041c153a59df5336f6e9a14a'/>
<id>f93d6bfbd2f74d79041c153a59df5336f6e9a14a</id>
<content type='text'>
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) &amp;&amp; C

    config BAR
           bool "BAR"
           depends on (A || B) &amp;&amp; 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-&gt;dep ==&gt; AND        BAR-&gt;dep ==&gt; AND        BAZ-&gt;dep ==&gt; OR
              /   \                   /   \                   /  \
            OR     C                OR     C                 A    B
           /  \                    /  \
          A    B                  A    B

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

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

The optimized data structure looks like this:

  FOO-&gt;dep, BAR-&gt;dep ==&gt; AND
                        /   \
         BAZ-&gt;dep ==&gt; 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) &amp;&amp; C, is calculated,
it can be cached, eliminating the need to recalculate it for BAR.

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

Signed-off-by: Masahiro Yamada &lt;masahiroy@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
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) &amp;&amp; C

    config BAR
           bool "BAR"
           depends on (A || B) &amp;&amp; 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-&gt;dep ==&gt; AND        BAR-&gt;dep ==&gt; AND        BAZ-&gt;dep ==&gt; OR
              /   \                   /   \                   /  \
            OR     C                OR     C                 A    B
           /  \                    /  \
          A    B                  A    B

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

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

The optimized data structure looks like this:

  FOO-&gt;dep, BAR-&gt;dep ==&gt; AND
                        /   \
         BAZ-&gt;dep ==&gt; 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) &amp;&amp; C, is calculated,
it can be cached, eliminating the need to recalculate it for BAR.

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

Signed-off-by: Masahiro Yamada &lt;masahiroy@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>scripts: move hash function from scripts/kconfig/ to scripts/include/</title>
<updated>2024-09-20T00:21:52+00:00</updated>
<author>
<name>Masahiro Yamada</name>
<email>masahiroy@kernel.org</email>
</author>
<published>2024-09-08T12:43:16+00:00</published>
<link rel='alternate' type='text/html' href='https://git.exis.tech/linux.git/commit/?id=a16219bdd34777cce35b9b6a704bfbaad28adb72'/>
<id>a16219bdd34777cce35b9b6a704bfbaad28adb72</id>
<content type='text'>
This function was originally added by commit 8af27e1dc4e4 ("fixdep: use
hash table instead of a single array").

Move it to scripts/include/ so that other host programs can use it.

Signed-off-by: Masahiro Yamada &lt;masahiroy@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This function was originally added by commit 8af27e1dc4e4 ("fixdep: use
hash table instead of a single array").

Move it to scripts/include/ so that other host programs can use it.

Signed-off-by: Masahiro Yamada &lt;masahiroy@kernel.org&gt;
</pre>
</div>
</content>
</entry>
</feed>
