preproc/symtable (preproc:symtable-complete): Do not re-process imported symbols

It's embarrassing how much time this saved on builds.

This apparently has always been doing a linear scan on the entire symbol
table for _every single param in the symbol table_, including those that
were imported.  This is not only unnecessary, but has no effect on the end
result of the system.

This cut build times almost in half, due to the number of symbols in some of
our packages.  All for unnecessary work.

Like most things that have quadratic (or polynomial) time complexity, they
don't show up during initial development, and are hard to even profile for,
because their effects are so small.  Now that our system has grown
substantially, it had a massive effect.

DEV-15114
main
Mike Gerwitz 2023-10-16 11:34:46 -04:00
parent c1770d39ff
commit b82294b1bd
3 changed files with 13 additions and 2 deletions

View File

@ -843,7 +843,8 @@
</template> </template>
<template match="preproc:sym[ @type='param' ]" mode="preproc:symtable-complete" priority="5"> <template mode="preproc:symtable-complete" priority="5"
match="preproc:sym[ @need-resolve-dtype='true' ]">
<param name="syms" as="element( preproc:sym )*" /> <param name="syms" as="element( preproc:sym )*" />
<!-- attempt to derive type information from a typedef --> <!-- attempt to derive type information from a typedef -->
@ -863,7 +864,7 @@
<!-- complete datatype with primitive --> <!-- complete datatype with primitive -->
<copy> <copy>
<sequence select="@*" /> <sequence select="@*[ not( local-name() = 'need-resolve-dtype' ) ]" />
<attribute name="dtype" select="$typedef/@dtype" /> <attribute name="dtype" select="$typedef/@dtype" />
</copy> </copy>
</template> </template>

View File

@ -345,11 +345,16 @@
<variable name="dim" as="xs:integer" <variable name="dim" as="xs:integer"
select="_symtable:str-to-dim( @set )" /> select="_symtable:str-to-dim( @set )" />
<!-- @need-resolve-dtype flags this symbol as needing further processing
to resolve @dtype, which we cannot do until we know we have a full
symbol table that includes the necessary typedef referenced by the
current value of @dtype -->
<preproc:sym type="param" <preproc:sym type="param"
name="{@name}" name="{@name}"
dim="{$dim}" dim="{$dim}"
desc="{@desc}" desc="{@desc}"
dtype="{@type}" dtype="{@type}"
need-resolve-dtype="true"
default="{@default}" default="{@default}"
tex="{@sym}" /> tex="{@sym}" />
</template> </template>

View File

@ -63,6 +63,7 @@
dim="1" dim="1"
desc="Vector param" desc="Vector param"
dtype="footype" dtype="footype"
need-resolve-dtype="true"
default="" default=""
tex="" /> tex="" />
@ -71,6 +72,7 @@
dim="2" dim="2"
desc="Matrix param with TeX" desc="Matrix param with TeX"
dtype="tex" dtype="tex"
need-resolve-dtype="true"
default="" default=""
tex="\tex" /> tex="\tex" />
@ -79,6 +81,7 @@
dim="0" dim="0"
desc="Scalar param (implicit)" desc="Scalar param (implicit)"
dtype="bar" dtype="bar"
need-resolve-dtype="true"
default="" default=""
tex="" /> tex="" />
@ -87,6 +90,7 @@
dim="0" dim="0"
desc="Scalar param (explicit)" desc="Scalar param (explicit)"
dtype="bar" dtype="bar"
need-resolve-dtype="true"
default="" default=""
tex="" /> tex="" />
@ -95,6 +99,7 @@
dim="-1" dim="-1"
desc="Unknown dimension" desc="Unknown dimension"
dtype="wtf" dtype="wtf"
need-resolve-dtype="true"
default="" default=""
tex="" /> tex="" />
</expect> </expect>