Could more namespaces improve compilation time?

84 views Asked by At

I work with a very large codebase (above 3K translation units) in which almost every declaration is under the same namespace. Occasionally, some sub-namespaces are declared, but it is definitely not the rule.

I was wondering: could compilation time benefit from having more namespaces? I was thinking mostly about Koenig Lookup, but I am not sure some other compilation steps might be affected as well.

For the general topic of increase compilation time, we went for the Unity Build approach.

About namespace topic, we did not really tried anything. It would require some very specific code generation logic to try to reproduce something measurable I guess. We would go that far if I find no good answer online.

1

There are 1 answers

1
user17732522 On

Using narrower namespaces may reduce the number of functions that need to be considered in overload resolution for argument-dependent lookup, however I would only in rare cases expect that to make a significant difference (e.g. if a lot of template instantiation is associated with the overload resolution).

In general I would not expect any performance impact, either positive or negative.