justinethier / cyclone

:cyclone: A brand-new compiler that allows practical application development using R7RS Scheme. We provide modern features and a stable system capable of generating fast native binaries.
http://justinethier.github.io/cyclone/
MIT License
825 stars 44 forks source link

Huge '.c' file when compiling bitwise arithmetic code #393

Closed arthurmaciel closed 4 years ago

arthurmaciel commented 4 years ago

@justinethier, when I try to compile a port of Chibi's md5 library the compiler takes a long time and produces a 7.8MB md5.c file with more than 150k lines of code.

You can reproduce it by running:

git clone https://github.com/arthurmaciel/md5.git
cd md5
cyclone-winds build-local ;; almost 2 minutes
cyclone-winds test-local

which yields and error when trying to (md5 "")

md5: !..
2 out of 3 (66.7%) tests passed in 0.0 seconds.
1 error (33.3%).
ERROR: (md5 "")
    ("Unable to open input memory stream" 22)Tests performed

Compiler times do not differ here between gcc 9.3.0 and clang 8.0.1:

# gcc9
time CC=/usr/local/bin/gcc9 cyclone-winds build-local
# 126,81s user 
# 1,17s system 
# 107% cpu 
# 1:59,31 total

# clang
time cyclone-winds build-local 
# 125,62s user 
# 1,31s system 
# 108% 
# cpu 1:57,41 total

I need this package in order to port the PostgreSQL one. But I am not sure I should add it considering its size. What do you think?

justinethier commented 4 years ago

The problem here is a massive explosion in program size during the CPS compilation phase. There is a LOT going on in (md5 src) including quite a few macro expansions. There may not be a good solution here. It may be more practical to implement the meat of this algorithm in C.

arthurmaciel commented 4 years ago

Thanks, @justinethier! I will accept the PR on MD5 package.