Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-enable precompilation for common Parsers routines #148

Merged
merged 4 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ version = "2.5.0"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
SnoopPrecompile = "66db9d55-30c0-4569-8b51-7e840670fc0c"

[compat]
SnoopPrecompile = "1"
julia = "1.6"

[extras]
Expand Down
35 changes: 29 additions & 6 deletions src/precompile.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
function _precompile_()
ccall(:jl_generating_output, Cint, ()) == 1 || return nothing
precompile(Tuple{typeof(Parsers.parse), Type{Int64}, String})
precompile(Tuple{typeof(Parsers.parse), Type{Float64}, String})
precompile(Tuple{typeof(Parsers.parse), Type{Date}, String})
using SnoopPrecompile

@precompile_setup begin
# Putting some things in `setup` can reduce the size of the
# precompile file and potentially make loading faster.
options = Parsers.Options()
pos = 1
val = "123"
len = length(val)
@precompile_all_calls begin
# all calls in this block will be precompiled, regardless of whether
# they belong to your package or not (on Julia 1.8 and higher)
for T in (String, Int32, Int64, Float64, BigFloat, Dates.Date, Dates.DateTime, Dates.Time, Bool)
for buf in (codeunits(val), Vector(codeunits(val)))
Parsers.xparse(T, buf, pos, len, options)
Parsers.xparse(T, buf, pos, len, options, Any)
end
end

for T in (Int32, Int64, Float64, BigFloat, Dates.Date, Dates.DateTime, Dates.Time, Bool)
for buf in (val, SubString(val, 1:3), Vector(codeunits(val)), view(Vector(codeunits(val)), 1:3))
try
Parsers.parse(T, buf, options)
catch
end
Parsers.tryparse(T, buf, options)
end
end
end
end
_precompile_()