On 2014-02-26, 4:52 AM, Neil wrote:
Ehsan Akhgari wrote:

On 2/23/14, 4:05 PM, Neil wrote:

Both ArrayLength and MOZ_ARRAY_LENGTH are typesafe when compiled as
C++, however ArrayLength has the disadvantage that it's not a
constant expression in MSVC. In unoptimised builds this is direly
slow as the templated function does not even get inlined, but even in
optimised builds the MSVC compiler is unable to completely optimise
away static variables. In particular, the variable is treated as if
it is forward-declared: the value is fetched from memory in each
function that uses it. (In my simple test there were enough registers
to avoid fetching the value more than once, but I don't know what
happens if this is not the case. And at least the optimiser was able
to avoid creating any static constructors.) Would it therefore be
preferable to use MOZ_ARRAY_LENGTH in such cases?

Which cases are those exactly?

The one that I spotted is that MSVC is unable to optimise static
variables, e.g. when you write static const length = ArrayLength(array);
If you write this as a local then the compiler is able to optimise it
away in release builds.

So you mean the problematic cases happen when that variable is at a global scope or something?

Note that I don't think that we need to care about the performance of
ArrayLength() in non-optimized builds.

Debug builds are now sufficiently slow that I no longer dogfood them,
but as it happens MSVC is able to optimise MOZ_ARRAY_LENGTH in both opt
and debug builds.

Wanting faster debug builds is a good thing. I doubt that the subject of this thread will give you those though. :-)

My suggestions: first, build with --enable-debug --enable-optimize. If that is still slow enough, try profiling the build and see what jumps at you as the biggest costly things we do, and file bugs about them.

On 2014-02-24, 1:25 PM, Chris Peterson wrote:

To avoid developers and reviewers from having to remember special
cases, maybe MOZ_ARRAY_LENGTH should just be the standard everywhere.

They're not quivalent.

Would you mind xpanding on that?

Sure. mozilla::ArrayLength has a special case for mozilla::Array <http://mxr.mozilla.org/mozilla-central/source/mfbt/ArrayUtils.h#52>.

Cheers,
Ehsan

_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to