Array append performance

bearophile bearophileHUGS at lycos.com
Fri Aug 22 19:23:04 PDT 2008


First of all thank you very much Sean Kelly for your clear explanation of the situation.

dsimcha:
> Other than the 4 bytes of extra overhead, does anyone see any downside to
> including a capacity field?  Also, is there some situation I'm not thinking of
> where the 4 bytes actually matter more than the speed gains in question?

In 2D/nD arrays you repeat such size_t many times, so it's not just 4/8 bytes.
(This particular problem can be solved with rectangular/equal length dynamic arrays, but it may be too much for a built-in type...).

Are dynamic array appends common? I think they may be used often enough to justify such memory increase.

I think an experimental approach here may be the best way to answer such question. I mean creating a branch version of DMD where dynamic arrays have a 3-item long defining struct (12/24) and use it to benchmark some real programs or benchmarks, to see how the performance in memory/speed of the compiler changes. How much time/work does it require to create a DMD with such change?

Note that a similar branched DMD can be useful to test the performance of another change Walter was talking regarding array structs: changing the len-ptr struct of the arrays to a startptr-stopptr struct.

Bye,
bearophile



More information about the Digitalmars-d mailing list