Skip to content

Using TVI0D with PeriodCalendar is very slow #186

@kmdeck

Description

@kmdeck

In our fluxnet simulations, we wish to construct the time varying input from observations. These observations are half hourly, and can last many years. For example, even one year of data consists of 4e5 points. It is convenient to use PeriodicBC (for spinup, etc).

In this case, this line becomes very slow
https://github.com/CliMA/ClimaUtilities.jl/blob/37bb7ab6ada77b749bacb245c9c2719479227cf1/ext/TimeVaryingInputs0DExt.jl#L112C42-L112C72

For example:

times = [ClimaUtilities.TimeManager.ITime(x; epoch =  DateTime(2008)) for x in 0:1:100];
@time [float.(promote(times...))...];
  0.256722 seconds (937.28 k allocations: 47.744 MiB, 3.62% gc time, 99.76% compilation time)
times = [ClimaUtilities.TimeManager.ITime(x; epoch =  DateTime(2008)) for x in 0:1:1000];
@time [float.(promote(times...))...];
  1.645448 seconds (3.61 M allocations: 234.321 MiB, 4.09% gc time, 98.11% compilation time)
times = [ClimaUtilities.TimeManager.ITime(x; epoch =  DateTime(2008)) for x in 0:1:10000];
@time [float.(promote(times...))...];
 33.065048 seconds (35.07 M allocations: 8.290 GiB, 3.95% gc time, 90.77% compilation time)

Simply converting to a float is much faster:

julia> f(x) = ClimaUtilities.float(x)
f (generic function with 1 method)
julia> @time f.(times);
  0.075337 seconds (208.04 k allocations: 10.002 MiB, 99.50% compilation time: 42% of which was recompilation)
julia> length(times)
10001

I thought the issue must be promote (which has to search a Tuple and do a bunch of conversions?), but this is much faster too:

julia> @time float.(promote(times...));
  3.098199 seconds (70.02 k allocations: 6.713 GiB, 22.16% gc time)

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