configure_file() could be made more efficient
In profiling results provided at #21703 (comment 898127), it was observed that configure_file()
was a non-trivial contributor to the time taken for FetchContent_MakeAvailable()
calls. Looking at the implementation of configure_file()
, it seems that when it needs to perform any kind of substitution, it reads the file line-by-line and also writes out to file line-by-line. It would probably be much more efficient to read the whole file in, process it line-by-line from the string read in and build up the result in a string, then only write out that whole string to file in one go at the end.
Other functions like file(CONFIGURE)
, etc. should probably also be checked to see if similar optimizations could be done there too, although configure_file()
is likely to be the most widely used and should be the primary focus initially.