On Wednesday, 27 June 2018 at 16:00:37 UTC, Mario Silva wrote:
Any tips on how to code in a way that minimizes both compilation times and memory consumption when compiling?

Here are my tips.  I'd love to hear more from others.

* Try to reduce imports. E.g., say you use a lot of stuff from std.algorithm in your implementations, but not in your external interface. In that case, instead of doing "import std.algorithm;" at the module top, do things like "import std.algorithm.searching : canFind;" inside function bodies. If you think about this when designing your external interfaces, you can let user code import what it needs from your modules without recursively importing half the rest of the D ecosystem with it.

* Templates are great, but not everything has to be one. Sometimes a simple delegate makes a perfectly generic interface. Templated code can be more expensive to compile, while non-templated code can be compiled once in a library and then reused.

* CTFE is awesome but currently a memory hog.

BTW, vibe.d isn't great with this stuff, TBH. Simple public API functions return types with "auto" that turn out to be several layers of templated wrappers all the way down, each wrapper coming from a different module. That's an example of what to avoid doing.

Reply via email to