rt/aaA.d Line: 553

Steven Schveighoffer schveiguy at gmail.com
Sat Feb 15 14:30:20 UTC 2020


On 2/15/20 6:49 AM, Ferhat Kurtulmuş wrote:
> On Friday, 14 February 2020 at 23:41:45 UTC, Steven Schveighoffer wrote:
>> On 2/14/20 6:36 PM, Ferhat Kurtulmuş wrote:
>>>      İf ((aa.used + 1)* GROW_DEN > aa.dim * GROW_NUM)
>>>          aa.grow(ti.key);
>>
>> This call is expensive (it reallocates all the buckets and reinserts 
>> all the existing data into the new bucket), it should be avoided if in 
>> the end we will not be incrementing used.
>>
> 
> I am trying to write a gc-free AA based on the original runtime code 
> (mem with malloc and free). My question is that why my version is slower 
> (about 1.5 times slower) than the runtime version?

Have you ensured you are using -inline, -O, and -release? This is how 
druntime is compiled.

> https://controlc.com/2e58c305
> 
> Those are some differences from runtime version:
> 
> - nogc and no typeid of course.
> - does not care about postblit of key types (don't need it, assume only 
> basic types are allowed for key type)

Postblit should be automatic for your code because you are doing the 
types directly.

> - runtime version uses typeid to do some alignments which are not 
> implemented in my version. Is that the reason why my code is slower?

No, alignments are important only if you don't have the type, which you 
do. The runtime uses void pointers and opaque structs, so it has to 
duplicate what the compiler is already doing for you.

Your code looks like a direct port, except for the allocations, so it 
should be as fast if compiled the same. Your code might even be faster, 
because it's going to be able to inline more aggressively. There may be 
issues with cache coherency, but I'm not sure how to find or diagnoce those.

I'll note that you are going to leak some memory because you are not 
freeing deleted buckets when you resize. In the GC version, the GC takes 
care of those.

-Steve


More information about the Digitalmars-d-learn mailing list