From eabfd9ea476bcbd8d06c9faaf7e9b20a7ce202c4 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Wed, 3 Apr 2024 12:27:24 -0400 Subject: [PATCH] Improve column read speed by removing type instability (#33) * explicitly type the column returned by getproperty to avoid column unioning * Extract type and char outside the array comprehension This takes runtime from 42 ms to 13 ms * Simplify code Co-authored-by: Rafael Schouten --------- Co-authored-by: Rafael Schouten --- src/DBFTables.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/DBFTables.jl b/src/DBFTables.jl index 2a8cb1c..841f4de 100644 --- a/src/DBFTables.jl +++ b/src/DBFTables.jl @@ -452,8 +452,9 @@ function Base.getproperty(dbf::Table, name::Symbol) nrow = header.records @inbounds field = getfields(dbf)[col] str = getstrings(dbf) - @inbounds colarr = [julia_value(field, str[col, i]) for i = 1:nrow] - return colarr + FT = field.type + FV = Val{field.dbf_type}() + return @inbounds Union{FT, Missing}[julia_value(FT, FV, str[col, i]) for i = 1:nrow] end