Inline optimization

Dennis dkorpel at gmail.com
Tue Feb 26 14:30:58 UTC 2019


On Tuesday, 26 February 2019 at 02:43:36 UTC, Michelle Long wrote:
> Given a function such as a computation that would benefit from 
> running at full speed, is it possible to optimize only that 
> function rather than the full program?
>
> That is, compile with debug but optimize specific code:
>
> pragma(optimize, "O3")
> auto fastAdd(A,B)

GCC has such a pragma, but as far as I know D compilers don't. 
The closest thing I found was the optimization strategy attribute 
in LDC:
https://wiki.dlang.org/LDC-specific_language_changes#.40.28ldc.attributes.optStrategy.28.22strategy.22.29.29

But it seems you can only disable, not enable optimizations with 
that.

What you can do in any case is put the performance critical code 
in a separate compilation unit (i.e. its own file) and compile 
that with optimizations and link it with the rest of the program 
compiled without optimizations. With a makefile that shouldn't be 
hard, though for expressing that in Dub I'm afraid you have to 
put it in its own sub package with an optimization flag in the 
'dflags' attribute.


More information about the Digitalmars-d mailing list