[m-rev.] for review: Cache module file names when writing dependency files.
Julien Fischer
jfischer at opturion.com
Thu Feb 2 16:20:42 AEDT 2023
On Thu, 2 Feb 2023, Peter Wang wrote:
> When writing out dependency files, the compiler would call
> module_name_to_file_name often for the same pairs of module name and
> file extension. Caching the results of those calls saves on
> constructing temporary strings.
>
> This change reduces the time to make dependencies in the compiler
> directory from 2.40 seconds to 2.15 seconds on my machine.
>
> compiler/write_deps_file.m:
> Add a predicate make_module_file_name that caches calls to
> module_name_to_file_name.
>
> Thread the cache map through the predicates in this module.
> Replace calls to module_name_to_file_name with calls to
> make_module_file_name when appropriate.
>
> diff --git a/compiler/write_deps_file.m b/compiler/write_deps_file.m
> index 30885a5c0..65f6acd68 100644
> --- a/compiler/write_deps_file.m
> +++ b/compiler/write_deps_file.m
> +make_module_file_name(Globals, From, Ext, ModuleName, FileName,
> + !Cache, !IO) :-
> + (
> + Ext = ext_src,
> + % No point caching these.
> + module_name_to_file_name(Globals, From, do_not_create_dirs,
> + Ext, ModuleName, FileName, !IO)
> + ;
> + Ext = ext_other(OtherExt),
> + ModuleNameExt = module_name_and_ext(ModuleName, OtherExt),
> + ( if map.search(!.Cache, ModuleNameExt, FileName0) then
> + FileName = FileName0
> + else
> + module_name_to_file_name(Globals, From, do_not_create_dirs,
> + Ext, ModuleName, FileName, !IO),
> + map.det_insert(ModuleNameExt, FileName, !Cache)
> + )
> + ).
I suggest adding a comment somewhere around saying that the rationale for this
caching is that it saves on temporary string construction.
Otherwise, that's fine.
Julien.
More information about the reviews
mailing list