Skip to content

Allocation in a simple sum over a named tuple allowing Missing #40768

@bkamins

Description

@bkamins

I was thinking if there is a way to avoid allocations in sum in the following case (they are killing performance in some practical cases):

julia> for j in 10:10:200
       nt = NamedTuple{ntuple(i -> Symbol("x", i), j), NTuple{j, Union{Missing, Float64}}}(ntuple(identity, j))
       sum(nt)
       @time sum(nt)
       end
  0.000001 seconds (25 allocations: 1.891 KiB)
  0.000004 seconds (45 allocations: 6.734 KiB)
  0.000003 seconds (65 allocations: 14.703 KiB)
  0.000003 seconds (85 allocations: 26.406 KiB)
  0.000004 seconds (105 allocations: 40.016 KiB)
  0.000029 seconds (125 allocations: 59.203 KiB)
  0.000032 seconds (145 allocations: 79.984 KiB)
  0.000041 seconds (165 allocations: 106.359 KiB)
  0.000062 seconds (185 allocations: 130.922 KiB)
  0.000065 seconds (205 allocations: 159.531 KiB)
  0.000061 seconds (225 allocations: 194.359 KiB)
  0.000076 seconds (245 allocations: 238.203 KiB)
  0.000056 seconds (265 allocations: 276.344 KiB)
  0.000056 seconds (285 allocations: 315.125 KiB)
  0.000064 seconds (305 allocations: 365.719 KiB)
  0.000067 seconds (325 allocations: 410.125 KiB)
  0.000077 seconds (345 allocations: 467.594 KiB)
  0.000081 seconds (365 allocations: 517.625 KiB)
  0.000086 seconds (385 allocations: 581.969 KiB)
  0.000101 seconds (405 allocations: 637.625 KiB)

CC @nalimilan

Metadata

Metadata

Assignees

No one assigned

    Labels

    foldsum, maximum, reduce, foldl, etc.missing dataBase.missing and related functionalityperformanceMust go faster

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions