It may be worth reminding people that this is not specific to DebugOnly but
general to all C++ classes: In C++, there is no such thing as a class with
size 0. So expecting DebugOnly<T> to be of size 0 is not misunderstanding
DebugOnly, it is misunderstanding C++. The only way to have empty classes
behave as if they had size 0, is to inherit from them instead of having
them as the types of members.That's called the Empty Base Class
Optimization.
http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Empty_Base_Optimization

Since DebugOnly<T> incurs a size overhead in non-debug builds, maybe we
should officially consider it bad practice to have any DebugOnly<T> class
members. Having to guard them in #ifdef DEBUG takes away much of the point
of DebugOnly<T>, doesn't it?

Benoit


2014-07-15 21:21 GMT-04:00 Nicholas Nethercote <n.netherc...@gmail.com>:

> Hi,
>
> The comment at the top of mfbt/DebugOnly.h includes this text:
>
>  * Note that DebugOnly instances still take up one byte of space, plus
> padding,
>  * when used as members of structs.
>
> I'm in the process of making js::HashTable (a very common class)
> smaller by converting some DebugOnly fields to instead be guarded by
> |#ifdef DEBUG| (bug 1038601).
>
> Below is a list of remaining DebugOnly members that I found using
> grep. People who are familiar with them should inspect them to see if
> they belong to classes that are commonly instantiated, and thus if
> some space savings could be made.
>
> Thanks.
>
> Nick
>
>
> uriloader/exthandler/ExternalHelperAppParent.h:  DebugOnly<bool> mDiverted;
> layout/style/CSSVariableResolver.h:  DebugOnly<bool> mResolved;
> layout/base/DisplayListClipState.h:  DebugOnly<bool> mClipUsed;
> layout/base/DisplayListClipState.h:  DebugOnly<bool> mRestored;
> layout/base/DisplayListClipState.h:  DebugOnly<bool> mExtraClipUsed;
> gfx/layers/Layers.h:  DebugOnly<uint32_t> mDebugColorIndex;
> ipc/glue/FileDescriptor.h:  mutable DebugOnly<bool>
> mHandleCreatedByOtherProcessWasUsed;
> ipc/glue/MessageChannel.cpp:    DebugOnly<bool> mMoved;
> ipc/glue/BackgroundImpl.cpp:  DebugOnly<bool> mActorDestroyed;
> content/media/MediaDecoderStateMachine.h:  DebugOnly<bool>
> mInRunningStateMachine;
> dom/indexedDB/ipc/IndexedDBParent.h:  DebugOnly<RequestType> mRequestType;
> dom/indexedDB/ipc/IndexedDBParent.h:  DebugOnly<RequestType> mRequestType;
> dom/indexedDB/ipc/IndexedDBParent.h:  DebugOnly<RequestType> mRequestType;
> dom/indexedDB/ipc/IndexedDBChild.h:  DebugOnly<RequestType> mRequestType;
> dom/indexedDB/ipc/IndexedDBChild.h:  DebugOnly<RequestType> mRequestType;
> dom/indexedDB/ipc/IndexedDBChild.h:  DebugOnly<RequestType> mRequestType;
> _______________________________________________
> dev-platform mailing list
> dev-platform@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-platform
>
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to