A idea to improve diet-ng compile speed!

Steven Schveighoffer schveiguy at gmail.com
Thu Aug 12 13:49:32 UTC 2021


On 8/12/21 3:55 AM, workman wrote:
> diet-ng is great and I love to use it,  but it is too slow to compile.
> 
> One idea to speedup is use preprocessor like DMD compile C header file 
> with GCC -E.
> 
> A diet-ng compiler write in D, translate template file into D source 
> code, then mixin from projects.  A runtime diet-ng compiler will easaly 
> speed up 1000 times compare to CTFE version, and you don't get any 
> performance loss.
> 
> A runtime diet-ng compiler also possible compile template into dynamic 
> library file,   you edit view files and a file monitor will recompile 
> the dynamic library then http server reload it, no need recompile full 
> projects.
> 
> Add new feature into diet will be more easy, since developer don't limit 
> to use CTFE code.
> 
> D CTFE is great, but not suit for task like dieg-ng.

diet-ng is really hard to deal with at runtime.

I added a feature that allows any *non-code* portions of the template to 
be reinterpreted at runtime, so for instance, if you want to add or 
remove an html class from an element, that is doable without rebuilding. 
I also created a [diet 
precompiler](https://code.dlang.org/packages/dietpc) to move most of the 
CTFE heavy-lifting to a pre-compilation step (it still runs a checksum 
on the files at compile-time, which is annoying to me, but I haven't 
bothered yet to strip that part out).

But changing the code means recompiling. And that is not always easy, 
because diet templates are compiled with specific context and aliases, 
which are not easy to replicate as a subpart of the project. I have 
considered splitting my routes out into individual subprojects to see if 
that helps with the build times.

With precompiling templates and live mode, diet-ng is at least tolerable 
for development.

If I were to do my own template system, with my experience in diet-ng, 
it would be focused on runtime interpretation (only a change to the 
input data structure or backend code would require a recompile) with the 
ability to compile everything for performance.

-Steve


More information about the Digitalmars-d mailing list