← Back to team overview

kicad-developers team mailing list archive

Re: CERN work package 4 (Extend number of layers)

 

On Thu, Jun 05, 2014 at 10:59:25PM +0200, Tomasz Wlostowski wrote:
> I'm not really proficient with Kicad's legacy code but my gut feeling is
> that impact of layer object on performance will not be as big as you're
> worrying. The performance-critical areas are interactive tools and
> rendering.

It wasn't me preoccupied of mask performance. In general whenever a pad
is somehow checked a mask is involved. But a good bit vector should not
be slow enough to notice...

(and by the way a while ago I finally redid the line clipper...
unexpectedly valgrind now tell me that much of the time is spend doing
heap management - malloc and friends; maybe there is some unwanted copy
around, or maybe is simply wx/gtk doing all these news/deletes)

The biggest trouble I would have with mask is initializing them
statically (i.e. literals). But many times the & operator with constant
is simply used to check if a single bit is set, so the following
transformation would be practical:

if (mask & LAYER_FRONT) 
    ==> 
if (mask.IsSet(LAYER_N_FRONT))

and obviously extended to

if (mask & (LAYER_FRONT | LAYER_BACK)) 
    ==> 
if (mask.IsSet(LAYER_N_FRONT) || mask.IsSet(LAYER_N_BACK))

another common idiom is:

if (mask & ::GetLayerMask(layer))
    ==>
if (mask.IsSet(layer))

Before I become a living peephole optimizer, I think that given
a sufficiently smart compiler and an inline definition of IsSet, it
should work fine (the last case could be potentially faster; however
AFAIK modern CPUs have at least one barrel shifter:P). The other
performance concern was about passing it by value... I think that with
adequate reference passing and constification much of the copying could
be elided by the compiler (C++ is *designed* to be used that way, so it
would be the first thing to be optimized) Heck, there is a special
rule for the return value optimization in the standard, too (the
compiler can elide a temporary copy or something like that).

Anyway, let's see where the discussion goes before deciding if it's
better to use uint64_t, std::bitset<n> or std::vector<bool> or something
home made (in probable performance order). After that more serious mask
experimentation could be done.

Also I couldn't care less if plotting is slow :D

-- 
Lorenzo Marcantonio
Logos Srl


References