[GSoC] 'Replace Runtime Hooks with Templates' progress and update thread
Seb
seb at wilzba.ch
Fri May 31 07:03:56 UTC 2019
On Thursday, 30 May 2019 at 19:20:36 UTC, rikki cattermole wrote:
> On 31/05/2019 4:45 AM, H. S. Teoh wrote:
>> On Thu, May 30, 2019 at 12:15:55PM +0000, Johannes Pfau via
>> Digitalmars-d wrote:
>> [...]
>>> Now regarding this specific GSoC project: I don't think we
>>> have to
>>> worry that this will affect compilation speed a lot. The
>>> compiler code
>>> will be mostly identical, only instead of calling an extern(C)
>>> function, it calls a template. Simple template instantiations
>>> are not
>>> particularily slow though, so this should not cause much of a
>>> slow
>>> down.
>>
>> That depends on how the template is implemented, doesn't it?
>> If there
>> are too many recursive templates, for example, the slowdown
>> can be quite
>> dramatic.
>>
>>
>>> There is however one side-effect: Unlike the extern(C)
>>> functions used
>>> before, template instances will be visible to the optimizer.
>>> This
>>> means that parts of these hooks can be inlined and optimized
>>> to
>>> improve performance. This however might affect compile time a
>>> bit.
>> [...]
>>
>> There's also the issue of code bloat, which should at least be
>> considered, even if actually solving it might complicate
>> things a bit
>> too much for GSoC. Previously copying an array from A to B
>> involved
>> only a single runtime function; now we're looking at O(n)
>> template
>> instantiations, which potentially translates to O(n) functions
>> that,
>> ostensibly, do the exact same copying of some number of bytes
>> from A to
>> B.
>
> Agreed, I'm worried about template bloat.
>
> But at the same time, I hope we can force inlining. If we can,
> that will solve that problem.
FWIW we have been doing this for years now (have a look at the
various templates in object.d, e.g. __cmp or __switch) and the
fact that no one noticed nor complained, shows that this is no
concern.
tl;dr: the compiler already generates a special template
everytime you do e.g. a switch, a cast, a comparison between
classes etc.
Examples:
- https://run.dlang.io/is/gsCSO1
- https://run.dlang.io/is/ti7rlu
There are many more.
More information about the Digitalmars-d
mailing list