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.

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.

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?

--
Warning: May contain traces of nuts.
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to