[m-rev.] for review: Speed up retrieval of foreign imports.

Julien Fischer jfischer at opturion.com
Wed Nov 23 13:56:20 AEDT 2022


On Wed, 23 Nov 2022, Peter Wang wrote:

> Speed up retrieval of foreign imports.
>
> For a do-nothing build of Prince with intermodule optimisation enabled,
> mmc --make spends a large fraction of its time computing foreign imports,
> or rather looking up the cached results of such. (There are 650 modules,
> and the results for each module are looked up tens to hundreds of
> thousands of times each.)
>
> This change replaces the representation of cached_foreign_imports from
> tree234 to one based on version_array. It reduces the average run time
> for a do-nothing build of Prince on my machine from 7.80 s to 5.87 s,
> for a speedup of ~25%.

Even better.

> compiler/va_map.m:
>    Add a simplified version of a module that I originally wrote for
>    Prince. I have permission to include it in the Mercury compiler and
>    assign copyright to the Mercury team.
>
> compiler/libs.m:
>    Include the new module in the libs package.
>
> compiler/make.deps_set.m:
>    Implement a typeclass needed to use module_index as a va_map key.
>
> compiler/make.dependencies.m:
>    Implement a typeclass needed to use maybe(T) as a va_map_value.
>
>    Use va_map to represent cached_foreign_imports instead of map.

...

> diff --git a/compiler/va_map.m b/compiler/va_map.m
> new file mode 100644
> index 000000000..6785dfc47
> --- /dev/null
> +++ b/compiler/va_map.m

...

> +:- pred maybe_grow_array(int::in, version_array(V)::in, version_array(V)::out)
> +    is det <= va_map_value(V).
> +
> +maybe_grow_array(Slot, Array0, Array) :-
> +    Size0 = size(Array0),

s/Size0/Size/

> +    ( if Slot >= Size0 then
> +        NewSize = roundup_array_size(Slot + 1),
> +        version_array.resize(NewSize, default_value, Array0, Array)
> +    else
> +        Array = Array0
> +    ).

Use state variables there.

That looks fine otherwise.

Julien.


More information about the reviews mailing list