Use pefile.PE(..., fast_load=True) where possible
fpq473 opened this issue · comments
delvewheel currently uses pefile via PEContext, which calls pefile.PE()
without enabling fast_load
. This means that all types of data directories are loaded/parsed. However, I noticed that many, if not all, uses of PEContext require only a subset of data directories. This means that a lot of work is not needed.
To avoid the extra work, pefile.PE() provides the fast_load=True
option, which skips parsing. For example, delvewheel.patch_dll.get_all_needed()
, which needs DIRECTORY_ENTRY_IMPORT
and DIRECTORY_ENTRY_DELAY_IMPORT
, can do something like:
pe = pefile.PE(lib_name, fast_load=True)
pe.parse_data_directories([
pefile.DIRECTORY_ENTRY['IMAGE_DIRECTORY_ENTRY_IMPORT'],
pefile.DIRECTORY_ENTRY['IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT'],
])
See the docstring of PE.parse_data_directories()
.
To provide some anecdata, on a rather large library containing thousands of symbols, parsing is sped up from around two minutes to under two seconds.