mir icon indicating copy to clipboard operation
mir copied to clipboard

C2M parsing speed could be improved

Open edubart opened this issue 3 years ago • 1 comments

I was comparing C2M compilation speed with GCC/Clang/TCC for compiling C2M itself, these are some numbers:

time gcc -std=gnu11 -Wno-abi -I. mir-gen.c c2mir/c2mir.c c2mir/c2mir-driver.c mir.c -ldl -lm -o a
real	0m3.592s
time clang -std=gnu11 -w -I. mir-gen.c c2mir/c2mir.c c2mir/c2mir-driver.c mir.c -ldl -lm -o a
real	0m2.314
time tcc -std=gnu11 -w -I. mir-gen.c c2mir/c2mir.c c2mir/c2mir-driver.c mir.c -ldl -lm -o a
real	0m0.093s
time ./c2m -I. c2mir/c2mir.c c2mir/c2mir-driver.c mir.c
real	0m0.722s

time ./c2m -I. -fsyntax-only c2mir/c2mir.c c2mir/c2mir-driver.c mir.c
real	0m0.406s

C2M seems much faster than GCC/Clang, but I was expecting C2M have somewhat similar compilation speed when comparing with TCC (both have simple and minimal C parsers), specially because C2M it is meant for JIT, but TCC still wins by a good margin. Notice, that just -fsyntax-only takes ~56% of the time in C2M in my tests, thus I guess there are many optimizations that could be done in the C parser in the future?

I am just sharing this in case nobody knew. Keep the good work!

edubart avatar Sep 25 '20 01:09 edubart

Thank your for sharing these numbers. C2M had never goals to be fast. My major goal was a quick implementation. I need c2m to generate MIR from C (Ruby source code) during building Ruby which is done once. After that the generated MIR code should be mixed with MIR code generated from Ruby bytecode and a machine code should be generated form the mixed code during JITting.

C2M is four pass compiler and its speed will never be close to TCC speed which is one pass compiler. Even if I speed up c2m in 10 times, MIR-generator will spend majority of all compilation time and still will be 3 times slower TCC. TCC has just a primitive code generator and does not make any optimizations.

C2M was originally planned as a byproduct of the MIR JIT compiler. But several people wrote me that they prefer C (or some higher level language) to MIR as a input to the JIT compiler. So I am thinking how to achieve this. In any case this problem will be not solved for the 1st release.

Thank you again for your feedback. Other people feedback is really useful for future project development directions.

vnmakarov avatar Sep 25 '20 14:09 vnmakarov