Am I do something wrong

Christopher Wright dhasenan at gmail.com
Thu Sep 13 09:43:25 PDT 2007


Eric Suen wrote:
> D not even a dynamic language, why const will affect runtime
> performance? besides, isn't all the LALR parser will using
> giant const arrays? for examples: seatd(http://seatd.mainia.de/)
> has a huge file called parser.d...

Look at the assembly yourself. It's quite obvious that dmd is doing 
constant expansion in a situation where any human would tell you that 
it's silly, and that this is creating a very bloated function that 
probably takes longer to load than the pagefault that reference 
semantics might cost.

I don't know how seatd works, or how efficient it is. I just looked at 
that example. It might be that, due to some strange quirks of dmd, seatd 
has large const arrays that work efficiently and your example has large 
const arrays that blow up.

More likely, seatd uses much smaller arrays, or does something to avoid 
making them const. Also, perhaps seatd uses one array at a time rather 
than doing array1[array2[array3[input]]]] sort of things.

As to why there's a performance difference (D not being dynamic is 
irrelevant to this), dmd expands compile-time constants. There's no 
pointer to take an offset of; you have to have a giant switch statement 
that returns a value depending on your input.


More information about the Digitalmars-d-learn mailing list