Hi, gfortran's handling of .mod files leaves a lot to be desired. One problem being that the parsing of the module is done in such a way that we seek back and forth in the file; see e.g. comments in PR 25708. This not only causes us to spend unnecessary time executing lseek syscalls, but we also read a lot more data than needed, as the typical stdio implementation discards any buffered data when the file is seeked.
Furthermore, I had a patch a year or so ago to reduce the size of the module files (PR 40958) by compressing them with zlib. Unfortunately this turned out to be unworkable since seeking in a zlib file is extremely inefficient (it appears to restart uncompression from the beginning of the file in order to count up to the right offset). To fix this I tried various approaches to parse module files without requiring seeking, but I was not successful in this. The attached patch takes the crude approach of first sequentially reading the .mod file into a temporary buffer, then does the actual parsing from that buffer. Testing on CP2K_2009-05-01.f90 (single-file version of CP2K for benchmarking purposes), the -fsyntax-only compile time drops from 55 seconds to 46, lseek syscalls drop from ~512k to 22k, read syscalls from 460k to 37k. This patch lays the groundwork for - zlib compression of .mod files (part 2/3). - Caching module files, a crude implementation of the old "module namespaces" idea. E.g. put the uncompressed module contents into a map keyed by module name. (part 3/3). Regtested on x86_64-unknown-linux-gnu, Ok for trunk? 2013-03-24 Janne Blomqvist <j...@gcc.gnu.org> PR fortran/25708 * module.c (module_locus): Use long for position. (module_content): New variable. (module_pos): Likewise. (prev_character): Remove. (bad_module): Free data instead of closing mod file. (set_module_locus): Use module_pos. (get_module_locus): Likewise. (module_char): use buffer rather than stdio file. (module_unget_char): Likewise. (read_module_to_tmpbuf): New function. (gfc_use_module): Call read_module_to_tmpbuf. -- Janne Blomqvist
tmpbuf.diff
Description: Binary data