Skip to content

Set operation (setdiff, union, intersect, symdiff) performance issues #40501

Open
@mtfishman

Description

@mtfishman

EDIT: This has morphed into a more general discussion about set operation performance, beyond the initial issue presented.

I'm finding that setdiff is slightly slower with exactly 2 inputs:

julia> versioninfo()
Julia Version 1.6.0
Commit f9720dc2eb (2021-03-24 12:55 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Xeon(R) E-2176M  CPU @ 2.70GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, skylake)
Environment:
  JULIA_EDITOR = vim

julia> @btime setdiff($([1, 2, 3]), $([1, 2]))
  284.924 ns (7 allocations: 624 bytes)
1-element Vector{Int64}:
 3

julia> @btime setdiff($([1, 2, 3]), $([1, 2]), $([]))
  158.302 ns (5 allocations: 592 bytes)
1-element Vector{Int64}:
 3

julia> @btime setdiff($([1, 2, 3]), $([1, 2]), $([]), $([]))
  167.004 ns (6 allocations: 608 bytes)
1-element Vector{Int64}:
 3

and the same on nightly:

julia> versioninfo()
Julia Version 1.7.0-DEV.931
Commit 29d5158d27* (2021-04-15 20:13 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Xeon(R) E-2176M  CPU @ 2.70GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, skylake)
Environment:
  JULIA_EDITOR = vim

julia> @btime setdiff($([1, 2, 3]), $([1, 2]))
  319.466 ns (8 allocations: 640 bytes)
1-element Vector{Int64}:
 3

julia> @btime setdiff($([1, 2, 3]), $([1, 2]), $([]))
  154.513 ns (5 allocations: 592 bytes)
1-element Vector{Int64}:
 3

julia> @btime setdiff($([1, 2, 3]), $([1, 2]), $([]), $([]))
  166.866 ns (6 allocations: 608 bytes)
1-element Vector{Int64}:
 3

It's not the case for Set inputs, so is probably caused by the generic code here. I've been staring at that code trying to figure out what would be special about inputting 2 Vectors and can't figure it out...

Metadata

Metadata

Assignees

No one assigned

    Labels

    collectionsData structures holding multiple items, e.g. setsperformanceMust go faster

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions