Hi!
My package PrettyTables.jl started to have a lot of configuration possibilities, which are handle by keyword arguments like:
function _pt_text(io::IO, pinfo::PrintInfo;
border_crayon::Crayon = Crayon(),
header_crayon::Union{Crayon,Vector{Crayon}} = Crayon(bold = true),
subheader_crayon::Union{Crayon,Vector{Crayon}} = Crayon(foreground = :dark_gray),
rownum_header_crayon::Crayon = Crayon(bold = true),
text_crayon::Crayon = Crayon(),
autowrap::Bool = false,
body_hlines::Vector{Int} = Int[],
body_hlines_format::Union{Nothing,NTuple{4,Char}} = nothing,
continuation_row_alignment::Symbol = :c,
crop::Symbol = :both,
crop_subheader::Bool = false,
crop_num_lines_at_beginning::Int = 0,
columns_width::Union{Int,AbstractVector{Int}} = 0,
equal_columns_width::Bool = false,
highlighters::Union{Highlighter,Tuple} = (),
hlines::Union{Nothing,Symbol,AbstractVector} = nothing,
linebreaks::Bool = false,
maximum_columns_width::Union{Int,AbstractVector{Int}} = 0,
minimum_columns_width::Union{Int,AbstractVector{Int}} = 0,
newline_at_end::Bool = true,
overwrite::Bool = false,
noheader::Bool = false,
nosubheader::Bool = false,
row_name_crayon::Crayon = Crayon(bold = true),
row_name_header_crayon::Crayon = Crayon(bold = true),
row_number_alignment::Symbol = :r,
screen_size::Union{Nothing,Tuple{Int,Int}} = nothing,
sortkeys::Bool = false,
tf::TextFormat = unicode,
title_autowrap::Bool = false,
title_crayon::Crayon = Crayon(bold = true),
title_same_width_as_table::Bool = false,
vlines::Union{Nothing,Symbol,AbstractVector} = nothing)
Those arguments depends on the backend (text, LaTeX, HTML). Hence, the API function is declared like this:
pretty_table(data; kwargs...) =
_pretty_table_select(stdout, data, []; kwargs...)
pretty_table(data, header::AbstractVecOrMat; kwargs...) =
_pretty_table_select(stdout, data, header; kwargs...)
# This definition is required to avoid ambiguities.
pretty_table(data::AbstractVecOrMat, header::AbstractVecOrMat; kwargs...) =
_pretty_table_select(stdout, data, header; kwargs...)
# This definition is required to avoid ambiguities.
pretty_table(io::IO, data::AbstractVecOrMat; kwargs...) =
_pretty_table_select(io, data, String[]; kwargs...)
pretty_table(io::IO, data; kwargs...) =
_pretty_table_select(io, data, String[]; kwargs...)
pretty_table(io::IO, data, header::AbstractVecOrMat; kwargs...) =
_pretty_table_select(io, data, header; kwargs...)
and so on.
I am having a problem related to compile time. To print the first table (a matrix), it takes here 1.6s, which is pretty good given the purpose of the package. The problem happens when I try to define a global configuration.
Since there are a lot of things that can be configured, I would like to have a global variable that holds the configuration so that the user can save what they want. Right now, it is stored as a dictionary:
Dict{Symbol,Any} with 2 entries:
:vlines => :all
:hlines => :none
Hence, I call the function to print the table by transforming this dictionary into a named tuple:
dictkeys = (collect(keys(conf.confs))...,)
dictvals = (collect(values(conf.confs))...,)
nt = NamedTuple{dictkeys}(dictvals)
# Print the table.
pretty_table(args...; nt...)
where conf.confs
is that dictionary and conf
is a global constant.
In this case, the time to print the first table goes to 5s! Is there any better way to do this so that it can be improved?
Sorry that I have not provided a MWE. I was not able to do this without actually copying a lot of PrettyTables.jl.