Alecsandru Patrascu added the comment:

I realize now that I should have explained a bit more the background of this 
patch. I'll do this now, for everyone to be clear of what is the effect of 
those flags.

This issue was revealed after running the coverage target over various 
workloads, for both CPython2 and CPython3. After running, it can be observed 
that there are functions in the interpreter that are not called at all over the 
lifespan of the interpreter. Even more, these functions occupy space in the 
resulting binary file, and the CPU is forced to jump to longer offsets than it 
is required. Furthermore, for production level binaries, it is a good idea to 
remove these stubs, as they bring no benefit. Now, in order to do this, in the 
first step, every function or data item must exist in its own section (and the 
flags -ffunction-sections and -fdata-sections come to help in GCC). In the 
second step, the linker comes into play and because it has the entire picture 
of every piece of data or function, it is able to see if there are functions 
that are never called for the current build (and the flag --gc-sections come to 
help).

This functionality is not unique or new and are used by default in other 
interpreters, such as V8/Node.JS in their Release target, to achieve exactly 
the same goal. Another example for behind the scene usage of this functionality 
is the Microsoft's compiler, which does it automatically in their 
interprocedural optimization phase.

To compress all of the above, the main reason for this speedup is the reduction 
of the code path length and having the useful function close together, so that 
the CPU will be able to prefetch them in advance and use them instead of 
trowing them away because they are not used.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue26285>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to