Skip to content

Instantly share code, notes, and snippets.

typedef T = int;
var segs: T**;
var seg: T*;
var segcap = 1;
var segidx = 1;
func grow() {
seg = 0;
asetcap(seg, segcap);
apush(segs, seg);
struct File {
base: Disposable;
libc_file: libc.FILE*;
}
func file_dispose(data: void*) {
self: File* = data;
if (self.libc_file) {
libc.fclose(self.libc_file);
}
func normalize_func(type: Type*): Type* {
key: char[];
num_params := alen(type.tfunc.params);
for (i := 0; i < num_params; i++) {
param := normalize(type.tfunc.params[i]);
acatn(key, (:char*)param, sizeof(param));
}
ret := normalize(type.tfunc.ret);
acatn(key, (:char*)ret, sizeof(ret));
normalized := agetn(normalized_funcs, key, alen(key));

We were having a discussion about compilation and linking performance on Twitter and I decided to do some measurements of the current Ion compiler, which is written in C. It's built via a main.c file that #includes everything else. The codebase contained 8,840 lines of code when I measured this. It only has a handful of external includes for the C standard library.

Here I'm doing a full rebuild with fast-debug flags, using the /Bt flag to give a timing breakdown between frontend, backend and link:

OptRef: Total time = 0.000s
OptIcf: Total time = 0.015s
Pass 1: Interval #1, time = 0.062s

Pass 2: Interval #2, time = 0.016s

typedef DisposeFunc = func(void*);
typedef DisposeMark = usize;
struct Disposable {
dispose: DisposeFunc;
mark: DisposeMark;
}
@threadlocal
var disposables: Disposable*[];
func noop_free(data: void*, ptr: void*) {
}
struct TempAllocator {
base: Allocator;
start: void*;
next: void*;
end: void*;
}
for (i := h) {
i &= index.mask;
if (slot := &index.slots[i]; slot.i == HASH_EMPTY || (slot.h == h && memcmp(a + slot.i*stride, x, size) == 0)) {
return slot;
}
i++;
}
struct NameNode {
len: uint32;
buf: char[1];
}
struct NameMap {
nodes: {uint64, NameNode*}[];
collisions: NameNode*[];
}
struct std_NameNode {
std_NameNode (*next);
uint32_t len;
char (buf[1]);
};
struct tuple4 {
ullong _0;
std_NameNode (*_1);
};
struct NameNode {
next: NameNode*;
len: uint32;
buf: char[1];
}
struct NameMap {
nodes: {uint64, NameNode*}[];
}