←back to thread

196 points svlasov | 1 comments | | HN request time: 0s | source
Show context
Dwedit ◴[] No.40851285[source]
Compile time or runtime? Compile time reflection would be completely painless and bloat-free.
replies(3): >>40851300 #>>40851330 #>>40851736 #
thechao ◴[] No.40851736[source]
Having implemented reflection in languages like C(++), before, it is most certainly not bloat-free. There are sorts of 'obvious' things programmers do (like enum-reflection) that end up injecting strings all over the place. The overhead is (worst case) proportional to the source-code size, in those cases. In other cases, you end up with bloat proportional to heavily-utilized template libraries. However, unless the reflection system is very clever, i.e., exposes enough information to the linker to strip duplicate-ish symbols, you end up with a bunch of reflection copies.
replies(2): >>40852644 #>>40852761 #
zarzavat ◴[] No.40852761[source]
I always thought it’s good practice in C/C++ to have only one translation unit in release builds e.g. SQLite amalgamations, instead of relying on LTO. It also speeds up compilation because it isn’t recompiling the same header files over and over again.
replies(2): >>40853586 #>>40854808 #
leni536 ◴[] No.40854808[source]
That's called a "unity build", build systems such as cmake support it. It has its pros and cons.
replies(1): >>40855558 #
1. account42 ◴[] No.40855558[source]
And while it helps with compile time (especially with mediocre compilers like MSVC where a large time is spent in the front-end), it doesn't help with stripping unneeded code/data compared to LTO.