Hi dev-platform,
I spent some time looking at include dependencies lately, and I think it
is an area where we can improve our code without too much effort.
Bad include dependencies lead to slower builds.
To give you an idea, we have a lot of headers that are pulled in many
many translation units, like 2D.h (the Azure API) that gets included in
about 27% of the translation units or jsapi.h that is included in 31.6%
of the translation units.
There's a lot more of these, but my point is not to list them here.
We should try to avoid including headers in other headers as much as
possible.
I noticed that in many case the header B.h is included in A.h because
class A contains a nsRefPtr<B>. We actually don't need the full
definition of B to do this, a forward reference is enough if you don't
use the ref pointer from the header in a way that will call AddRef or
Release. I wrote a page on MDN explaining how to do it:
https://developer-new.mozilla.org/en-US/docs/Developer_Guide/Include_dependencies
It is not obvious that we can do forward references with ref pointers,
but once we know about it, it is very simple to avoid these useless
include dependencies.
I also see that some headers included just for enum values, like the
enums defined in gfxASurface.h. The problem here is that gfxASurface is
already including stuff like nsThreadUtils.h, etc. You end up uncluding
a lot of things that are not related to this translation unit just
because you need to use enums in a function protoype (not even actually
using gfxASurface).
So I think It would be better to declare enums that are likely to be
used a lot in a separate file that does not import thousands of lines of
code.
I am not sure whether it is worth fixing existing code to get saner
depencies, but it is easy to not make these mistakes in future code
additions, so we should pay a little attention to this detail. David
Zbarsky landed a patch to reduce the number of files including Layers.h,
it went from 30% of the TUs down to only 6%.
maybe these guidelines (about nsRefPtr and enums described in the MDN
page) should be documented in the coding style guide as well?
Any thoughts?
Nicolas Silva
_______________________________________________
dev-platform mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-platform