arithy / packcc

A parser generator for C
Other
347 stars 28 forks source link

Avoid resizing empty capture and value tables #70

Closed dolik-rce closed 1 year ago

dolik-rce commented 1 year ago

I have noticed that PackCC generates calls to pcc_value_table__resize and pcc_value_table__resize even when there are no captures or values respectively.

I'd expect this to have no measurable impact, as the first instruction in the function is actually checking if the resize is needed. But benchmarking shows, that it is actually measurable and that avoiding the function calls results in consistent speed improvement of couple percent:

$ RUN_REPEATS=200 benchmark/benchmark.sh origin/master optimize-table-resizing
...
Run performance:
================
            origin/master                   optimize-table-resizing         
calc        132 ms (100%)   258 MB (100%)   132 ms (99%)    250 MB (96%)    
json        33 ms (100%)    101 MB (100%)   33 ms (98%)     101 MB (99%)    
kotlin      245 ms (100%)   410 MB (100%)   234 ms (95%)    409 MB (99%)    

I have tested it with gcc 13 and clang 16, both with -O2.

arithy commented 1 year ago

Thanks as always!