arocc icon indicating copy to clipboard operation
arocc copied to clipboard

Quadratic behavior in Parser

Open ehaas opened this issue 3 years ago • 0 comments

I have this simple python script to generate a C file with a lot of structs:

import sys
for i in range(int(sys.argv[1])):
    print(f"struct S{i} {{int x; int y; int z; }};")

Built the compiler with -Drelease-fast=true

➜  ~ python3 makestructs.py 10000 | /usr/bin/time  arocc ->/dev/null
        0.51 real         0.44 user         0.00 sys
➜  ~ python3 makestructs.py 20000 | /usr/bin/time  arocc ->/dev/null
        1.68 real         1.59 user         0.01 sys
➜  ~ python3 makestructs.py 40000 | /usr/bin/time  arocc ->/dev/null
        6.53 real         6.42 user         0.03 sys
➜  ~ python3 makestructs.py 80000 | /usr/bin/time  arocc ->/dev/null
       26.43 real        26.23 user         0.07 sys
➜  ~ python3 makestructs.py 160000 | /usr/bin/time  arocc ->/dev/null
       97.39 real        96.93 user         0.19 sys

Some quick profiling suggests that it's due to SymbolStack.defineTag iterating through all the struct definitions each time it adds a new one.

ehaas avatar Jun 30 '22 03:06 ehaas