Skip to content

Extra allocations from multiplication (redefining functions in the REPL alleviates allocations) #435

@OlivierHnt

Description

@OlivierHnt

This is a follow-up of this discussion in discourse.

Multiplication of intervals in functions defined inside a module leads to 6 extra allocations per *. Interestingly, redefining the function in the REPL fixes the issue.

Here is a MWE:

module MyModule
    foo(x) = x*x
    export foo
end

using .MyModule, IntervalArithmetic, BenchmarkTools

x = @interval(π);

@btime foo(Ref($x)[]);
# 137.597 ns (6 allocations: 96 bytes)

MyModule.foo(x) = x*x

@btime foo(Ref($x)[]);
# 59.040 ns (0 allocations: 0 bytes)

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