A idea to improve diet-ng compile speed!

Steven Schveighoffer schveiguy at gmail.com
Thu Aug 12 14:51:28 UTC 2021


On 8/12/21 10:11 AM, workman wrote:
> On Thursday, 12 August 2021 at 13:49:32 UTC, Steven Schveighoffer wrote:
> 
>> 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.
> 
> 
> Mixed d code with views made vibe.d like old PHP code, it hard to 
> maintain if business logic change fast, and not easy to testing.
> 
> 
> I am consider use a javascript server side render template like
> 
> 
> 
> On Thursday, 12 August 2021 at 14:04:03 UTC, Steven Schveighoffer wrote:
>> On 8/12/21 9:45 AM, workman wrote:
>> From experience, I think the 2 hours is probably not because of diet 
>> CTFE interpretation. But I could be wrong, I don't know what your 
>> application is like.
> 
> Not really take hours, but very slow and require a lot memory.

OK. My experience is that precompiling templates and using the cache 
feature reduced my build time from 38 seconds to 11, and also reduced 
memory consumption quite a bit. However, you still must build production 
without these modes. I would like to introduce a production 
precompilation mode, where the diet processing is done separately, and 
the code just imports the file without having to checksum it. But I 
haven't had the need yet.

If you have memory constraints that prevent you from building 
production, this might be a viable path.

> 
> 
>> diet supports layout inheritance via the `extends` directive.
>>
>> e.g. all my files look like:
>>
>> ```pug
>> extends layout
>> block extraCss
>>   // extra css includes
>> block extraJs
>>   // extra js includes
>> block content
>>   // page content
>> ```
> 
> 
> Thanks for the tips, I will try extends. What will be really nice is 
> some thing like:
> 
> ```twig
> {% extends "base.html" %}
> 
>      {% block sidebar %}
>          <h3>Table Of Contents</h3>
>          ...
>          {{ parent() }}
>      {% endblock %}
>      ```

Yes, that is exactly what `extends` does. Same keywords even. See 
[docs](https://github.com/rejectedsoftware/diet-ng/blob/master/SPEC.md#extension-includes) 
(they are a bit sparse, but there's an example there to help you 
understand how to do it).

-Steve


More information about the Digitalmars-d mailing list