JuliaGraphics / Colors.jl

Color manipulation utilities for Julia
Other
200 stars 44 forks source link

Optimize `colormap` #509

Closed kimikage closed 2 years ago

kimikage commented 2 years ago

This uses Tuple instead of Vector for the colormap parameters. (cf. https://github.com/JuliaGraphics/Colors.jl/commit/ddfe8d5f3aa69bdc566d28c82b81446575735a86) This also unifies the type of preset values to Float64.

However, at present, there is no speed improvement. :sob: I will make some more tweaks and add some tests. This is more of a compilation time issue than a runtime performance issue. I am guessing that there is some relation between the precompilation problem with colormap and #496.

before

julia> using Colors

julia> @time colormap("RdBu", 100);
  0.356729 seconds (1.47 M allocations: 87.943 MiB, 8.93% gc time, 99.93% compilation time)

julia> @time colormap("RdBu", 100);
  0.000067 seconds (916 allocations: 39.406 KiB)

julia> @time colormap("Blues", 100);
  0.000056 seconds (656 allocations: 25.875 KiB)

julia> @time colormap("RdBu", 100, logscale=true);
  0.009631 seconds (55.90 k allocations: 3.555 MiB, 99.07% compilation time)

julia> @time colormap("RdBu", 100, mid=0.7);
  0.000111 seconds (916 allocations: 41.219 KiB)

after (w/o PR #511)

julia> using Colors

julia> @time colormap("RdBu", 100);
  0.069386 seconds (605.76 k allocations: 38.593 MiB, 17.43% gc time, 99.91% compilation time)

julia> @time colormap("RdBu", 100);
  0.000025 seconds (30 allocations: 6.031 KiB)

julia> @time colormap("Blues", 100);
  0.000021 seconds (16 allocations: 3.000 KiB)

julia> @time colormap("RdBu", 100, logscale=true);
  0.012442 seconds (55.02 k allocations: 3.522 MiB, 99.67% compilation time)

julia> @time colormap("RdBu", 100, mid=0.7);
  0.000029 seconds (30 allocations: 6.016 KiB)

after (w/ PR #511)

julia> using Colors

julia> @time colormap("RdBu", 100);
  0.000042 seconds (6 allocations: 5.281 KiB)

julia> @time colormap("Blues", 100);
  0.000019 seconds (4 allocations: 2.625 KiB)

julia> @time colormap("RdBu", 100, logscale=true);
  0.008044 seconds (54.99 k allocations: 3.521 MiB, 99.62% compilation time)

julia> @time colormap("RdBu", 100, mid=0.7);
  0.000032 seconds (6 allocations: 5.266 KiB)

This also fixes the problem with hue interpolation. colormap_hue

codecov[bot] commented 2 years ago

Codecov Report

Merging #509 (2466f17) into master (2b553ad) will decrease coverage by 0.05%. The diff coverage is 94.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #509      +/-   ##
==========================================
- Coverage   94.07%   94.01%   -0.06%     
==========================================
  Files           9        9              
  Lines        1249     1270      +21     
==========================================
+ Hits         1175     1194      +19     
- Misses         74       76       +2     
Impacted Files Coverage Δ
src/precompile.jl 0.00% <0.00%> (ø)
src/utilities.jl 95.23% <50.00%> (-0.37%) :arrow_down:
src/colormaps.jl 96.85% <94.93%> (+2.06%) :arrow_up:
src/algorithms.jl 75.00% <100.00%> (-0.48%) :arrow_down:
src/conversions.jl 99.42% <100.00%> (+<0.01%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 2b553ad...2466f17. Read the comment docs.

kimikage commented 2 years ago

Remaining problems:

These can be tackled in separate PRs, though.