Skip to content

Avoiding invalidations of min/max  #168

@kimikage

Description

@kimikage

The following methods with Vararg invalidate Base.min(a, b, c, xs...) and Base.max(a, b, c, xs...).

Base.min(groups::BenchmarkGroup...) = mapvals(min, groups...)
Base.max(groups::BenchmarkGroup...) = mapvals(max, groups...)

I think the min and max with N > 2 arguments are very primitive methods, so we should avoid the invalidations.

Usually, the compilation time is not the target of benchmarks, and in this case, the invalidations are caused by specialization with the type defined in BenchmarkTools. Therefore the invalidation should not affect benchmark results. However, although I don't know the reasons, recompiling a precompiled method can lead to different native code, i.e. have side-effects.

A simple way to avoid the invalidations is to change the definitions to:

Base.min(g1::BenchmarkGroup, g2::BenchmarkGroup) = mapvals(min, g1, g2)
Base.max(g1::BenchmarkGroup, g2::BenchmarkGroup) = mapvals(max, g1, g2)

This may cause performance degradation, but we can also use minimum/maximum. IMO, reducing strange side-effects is more important.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions