Need for speed
Jon Degenhardt
jond at noreply.com
Fri Apr 2 02:36:21 UTC 2021
On Thursday, 1 April 2021 at 19:55:05 UTC, H. S. Teoh wrote:
> On Thu, Apr 01, 2021 at 07:25:53PM +0000, matheus via
> Digitalmars-d-learn wrote: [...]
>> Since this is a "Learn" part of the Foruam, be careful with
>> "-boundscheck=off".
>>
>> I mean for this little snippet is OK, but for a other projects
>> this my be wrong, and as it says here:
>> https://dlang.org/dmd-windows.html#switch-boundscheck
>>
>> "This option should be used with caution and as a last resort
>> to improve performance. Confirm turning off @safe bounds
>> checks is worthwhile by benchmarking."
> [...]
>
> It's interesting that whenever a question about D's performance
> pops up in the forums, people tend to reach for optimization
> flags. I wouldn't say it doesn't help; but I've found that
> significant performance improvements can usually be obtained by
> examining the code first, and catching common newbie mistakes.
> Those usually account for the majority of the observed
> performance degradation.
>
> Only after the code has been cleaned up and obvious mistakes
> fixed, is it worth reaching for optimization flags, IMO.
This is my experience as well, and not just for D. Pick good
algorithms and pay attention to memory allocation. Don't go crazy
on the latter. Many people try to avoid GC at all costs, but I
don't usually find it necessary to go quite that far. Very often
simply reusing already allocated memory does the trick. The blog
post I wrote a few years ago focuses on these ideas:
https://dlang.org/blog/2017/05/24/faster-command-line-tools-in-d/
--Jon
More information about the Digitalmars-d-learn
mailing list