Question

Does putting code in unnamed namespaces improve linker performance in any way?

Theoretically, the linker has less data to deal with when linking object files that were produced from different compilation units. However, does the VC++ linker's performance actually benefit from putting my code in un-named namespaces?

Was it helpful?

Solution

I asked the same question here, and got the following answer from a Microsoft representative:

That will save some symbol lookup time at best. I think it's reasonable to expect that symbol lookup uses a hashtable or other efficient enough data structure and the number of symbols doesn't affect link time significantly.

Besides, a quick look at a .obj file that contains unnamed namespaces shows that the members of such a namespace still have external linkage (that appears to be a bug, as far as I can tell they're supposed to have internal linkage) so they still contribute to the global scope symbol table.

So even if it could save time of building "the hash table with symbols that participate in cross-obj-file linkage" it would not matter, as those symbols are still marked to participate in external linkage.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top