JuliaImages / JuliaImages/juliaimages.github.io

document the performance caveat on abstract eltype

Open
#145 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

best practice
Dominant language
Julia
Stars
33
Forks
52
PR merge metrics
No merged PRs in 30d

Description

Gray.(img) is used widely tha Array{Gray, 2}(undef, sz...) or zeros(Gray, sz) becomes very alluring. However, there's a significant performance gap here:

julia> @btime zeros(Gray, 100, 100);
  39.331 μs (10002 allocations: 234.45 KiB)

julia> @btime zeros(Gray{N0f8}, 100, 100);
  2.565 μs (1 allocation: 9.94 KiB)

julia> @btime Array{Gray, 2}(undef, 100, 100);
  1.841 μs (2 allocations: 78.20 KiB)

julia> @btime Array{Gray{N0f8}, 2}(undef, 100, 100);
  127.157 ns (1 allocation: 9.94 KiB)

This is probably a JuliaImages specific confusion, because when we write Array{AbstractFloat, 2} we know it's an abstract type. But for Gray it's very likely that users don't get this.

Ref: https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-abstract-container-1

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Julia performance-tips section linked in the issue and review the existing JuliaImages documentation for discussion of Gray and array construction. Document that abstract Gray containers can be substantially slower than concrete Gray{N0f8} containers, using the reported examples as context. Done means the caveat and the distinction between Gray and Gray{N0f8} are clearly explained in the appropriate documentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
documentation, performance
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.