logoalt Hacker News

levodelellisyesterday at 9:09 PM2 repliesview on HN

I measured once and to my surprise templates aren't (directly) the reason for long compile times. It's function bodies in headers, and obviously templates are in headers and they call other templated functions/classes which explodes code generation and time. But if it's only a few lines and doesn't call other templated functions it's likely fine. I wrote about it here https://bolinlang.com/wheres-my-compile-time

After writing that, I wrote my own standard library (it has data structs like vector, hashmap and sets; slices, strings, rng, print, some io functions, and more) which uses a lot of templates, and it compiles in <200ms on both clang and gcc. Many standard library headers take much longer to compile than that. It's not a terrible idea to have your own standard lib if you need quick compile times.


Replies

rustyhancockyesterday at 10:19 PM

Another option can be if you have a core set of headers your project will use (and is stable) just precompiling them.

direwolf20yesterday at 10:11 PM

Your website seems to be blocking Tor

show 1 reply