A Friendly Challenge for D

Bastiaan Veelo Bastiaan at Veelo.net
Thu Nov 8 18:49:35 UTC 2018


Hi Jabari,

On Wednesday, 7 November 2018 at 20:30:33 UTC, Jabari Zakiya 
wrote:
> Hey Vijay I got a complete D version running correctly.
>
> https://gist.github.com/jzakiya/ae93bfa03dbc8b25ccc7f97ff8ad0f61

I cloned this and enabled P17 for you, get it at 
https://github.com/veelo/twinprimes_ssoz

I basically optimized the compile time table generation by 
removing templates and avoiding reallocations. This is a big deal 
because currently the compiler will not collect its own garbage. 
You'll see that I reserve exactly the minimum array lengths; of 
course I didn't know these when I started, I got it to work just 
by preallocating for up to P13 and using appender for P17. But 
since I now know the exact required length, I can just as well 
use it. My system has 16GB of RAM, which is enough.

[...]
> One thing that could|should make it faster is the use of fast 
> bitarrays to create the seg arrays in the threads (vs byte 
> arrays). I didn't find anywhere that D has a native bitarray 
> structure (Nim doesn't either).

There is https://dlang.org/phobos/std_bitmanip.html#BitArray

I haven't looked at the run-time code, it is very well possible 
that similar optimizations are possible there too.


More information about the Digitalmars-d mailing list