r/Compilers • • Aug 18 '26

Is 76 μs acceptable compilation performance for a almost prod ready ELF64 compiler?

Folks! Is this acceptable performance for a compiler? it do lexing, parsing, type checking, optimziing and codegen . It simply emits the ELF64 executable directly and runs it without an external linker/object-file pipeline.

--- CODEGEN RESULTS ---

Total Machine Bytes Emitted: 47 bytes

Compilation Speed: 76000 ns

Runnable ELF64 Machine Code Executable Written: boo

0 Upvotes

37 comments sorted by

3

u/Professional_Cell44 Aug 18 '26

well, it depends on:

- language spec: how complex your language is?
- source code(input): how big the souce code is? how complex is it?

and its only 47 bytes written, so i think it is quite tiny

0

u/Retired-69 Aug 18 '26

The specs align 89℅ with c23 , and also involve concurrency,  features for building LLM engines, OS etc. I would say complex. It's also  handle memory safety differently. That's the radical part. 

I agree 47 bytes is tiny and the example I parsed was dealing with macros.  Without macros it would compile same source around 43000 ms. 

For larger code like 60K LOC it finish in around 4-5 ms

2

u/Professional_Cell44 Aug 18 '26

then i think it has good performance; but ask your code agent to compare it against official compiler benchmarks

you may need to write similar code to be fair

1

u/MithrilHuman Aug 19 '26 edited Aug 19 '26

Programs, including compilers, can have slow start but perform well on large inputs. A program can perform well on small inputs but struggle with large ones. A microbenchmark is fine but real world applications are way larger than what you’re testing for. You should collect more data.

1

u/Retired-69 Aug 19 '26

You are right, but until now I couldn't test current code on millions of LOC even it's designed to scale, because that kind of code simply doesn't exist. This is not C even I'm aiming for 90℅ parity

1

u/GoblinsGym Aug 28 '26

Sounds good. What do you do in the way of optimization / register selection ?

1

u/Retired-69 Aug 29 '26

Funny you ask. I was actually 99% ready to show off a new langauge demo when I posted this , but I got a setback coz I thought Reddit users would react on a optimized, but not fully Clang -03 optimzied compiler. To answers you short. LSFE. It's my own engine optimized for single pass and so far parity with clang --02 and --03 and no LLVM, SSA, CFG. Within a month hopefully the demo will be pushed online.

1

u/GoblinsGym Aug 29 '26

I am looking forward to seeing more details on it, register selection has been an obstacle for my own project. My approach is based on a stack based IR, no AST.

Gcc / Clang compilers are a mystery - sometimes they are fiendishly clever, sometimes the code looks rather wasteful. I don't really expect a compiler to rewrite bad code for me, and appreciate some predictability.

1

u/Retired-69 Aug 30 '26

I'm surprised because you mentioned IR, no AST. That's the right direction if you want to gain performance, but stack based IR? How did you archieve that? It sounds like a perf killer to me.

Anway my compiler have no AST either, only IR so looks like we got something in common :)

GCC / CLANG got optimzied for all possible chips and bloated, so hard to track. I am only dealing with X64, ARM64, RISC-V and right now optional CLI flag for upcoming Zen 6.

1

u/Retired-69 Aug 30 '26

What is your issue with register selection? Lowering? DCE? or are you not getting
B8 D0 02 00 00 C3 as finale result?

1

u/GoblinsGym Aug 30 '26

Just the overall complexity of tracking data flow. I don't want to do full blown SSA.

Stack based IR makes things a little more complicated, but the stack is primarily within expressions. My IR uses fixed length words (12 bytes per IR word) to allow scanning forward and backward, and should also make it quite easy to recognize common subexpressions.

One thing I envision for register selection is to have "magnetic pull" for things that should end up in a specific register (e.g. call parameters passed in registers, shift counts for x64 etc)

Dead code elimination is not that bad, a lot of that happens already during parsing / IR generation.

1

u/Retired-69 Aug 30 '26

See if this help you. A short first draft about my LSFE. The version I'm using have evolved since then

https://hackmd.io/@cloacajackie123/SJoqfHYvzl

What lanaguage are you using for this? I am using my own.

→ More replies (1)

1

u/Retired-69 Aug 31 '26

A suggestion for you: look at LLVM/Rust’s approach. They often treat `u1`/`u4` as full `u8`/`i32` values in registers, wasting space and causing spills. If your IR/backend allows it, try packing multiple logical variables into one physical register.

1

u/GoblinsGym Aug 31 '26

My main target is embedded, e.g. ARM Thumb. 32 bit operations are the most efficient, 8 or 16 bit values are second class citizens. It certainly makes sense to track what bits you actually care about to decide whether you need to zero / sign extend or not.

Extracting bit fields always means some overhead, not every CPU flavor has the nice bit field extract / insert instructions.

For ARM Cortex M0 / M23 you also have the constraint that only r0..r7 are easy to access, r8..r12 are limited use only.

→ More replies (1)

3

u/[deleted] Aug 18 '26

[removed] — view removed comment

1

u/Retired-69 Aug 18 '26

To be honest I prefer the benchmarks to tell their own story when this is done, but at current stage it is only 5-6 times faster than TCC not 15 times :) This happen because TCC was from 2004 and both CPU architecture and general knowledge have changed since back then. For example TCC scans input byte-by-byte; IC scans 8 bytes at a time using SWAR, reducing per-character processing overhead.

The reason I am not faster than that is becaue I do analyzer, optimizer and codegen as well on the go.

The numbers are realistic and time will tell.

1

u/[deleted] Aug 18 '26

[removed] — view removed comment

1

u/Retired-69 Aug 18 '26

I will try it. Your compiler is single pass or two pass as in Tiny C? 

1

u/[deleted] Aug 18 '26 edited Aug 18 '26

[removed] — view removed comment

1

u/Retired-69 Aug 18 '26

I had to write a benchmark on the fly here and I had to use prev gen compiler that I
now use to finalize R3 with,. R3 performs better, but not syntax complete yet. And R2 is multi pass

```text

IC R2 Front-End Pipeline Stage Benchmark

Scope: Physical File I/O, Parse & Name-Resolve Stages

========================================================

Opening 'benchmark_input.txt' on physical storage...

Successfully loaded 12000000 bytes from disk.

--- Compilation Pipeline Breakdown ---

Load Stage (Disk I/O): 11 ms

Parse Stage (Scan): 54 ms

Name Resolve (Hash): 246 ms

--------------------------------------

Total Pipeline Time: 311 ms

Processed Lines: 500000 lines

Throughput Speed: 1602990 lines/sec

Bandwidth (Decimal): 38 MB/s (10^6 bytes/sec)

Bandwidth (Binary): 36 MiB/s (2^20 bytes/sec)

----------------------------------------

``

3

u/Slow-Mechanic-7427 Aug 18 '26 edited Aug 18 '26

Per their own post/comment history, they have nearly 4 decades experience in the "software industry" with most of that spent on programming languages, compilers, runtimes, and low-level systems per abother comment of theirs.

Its incredibly sus, id say.  Nearly 40 years of experience, with most of that extremely relevant to the topic, yet these are the questions and claims being presented?

1

u/AliceCode Aug 24 '26

The ELF64 header itself is 144 bytes.