Skip to content

Commit 86fb137

Browse files
add an offline precompile workload
1 parent b7f5aa8 commit 86fb137

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ LoggingExtras = "e6f89c97-d47a-5376-807f-9c37f3926c36"
1414
MbedTLS = "739be429-bea8-5141-9913-cc70e7f3736d"
1515
NetworkOptions = "ca575930-c2e3-43a9-ace4-1e988b2c1908"
1616
OpenSSL = "4d8831e6-92b7-49fb-bdf8-b643e874388c"
17+
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
1718
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1819
SimpleBufferStream = "777ac1f9-54b0-4bf8-805c-2214025038e7"
1920
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
@@ -27,6 +28,7 @@ ExceptionUnwrapping = "0.1"
2728
LoggingExtras = "0.4.9,1"
2829
MbedTLS = "0.6.8, 0.7, 1"
2930
OpenSSL = "1.3"
31+
PrecompileTools = "1.2.1"
3032
SimpleBufferStream = "1.1"
3133
URIs = "1.3"
3234
julia = "1.6"
@@ -37,9 +39,9 @@ Deno_jll = "04572ae6-984a-583e-9378-9577a1c2574d"
3739
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
3840
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
3941
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
42+
NetworkOptions = "ca575930-c2e3-43a9-ace4-1e988b2c1908"
4043
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
4144
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
42-
NetworkOptions = "ca575930-c2e3-43a9-ace4-1e988b2c1908"
4345

4446
[targets]
4547
test = ["BufferedStreams", "Deno_jll", "Distributed", "InteractiveUtils", "JSON", "Test", "Unitful", "NetworkOptions"]

src/HTTP.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,4 +631,9 @@ function Base.parse(::Type{T}, str::AbstractString)::T where T <: Message
631631
return m
632632
end
633633

634+
# only run if precompiling
635+
if ccall(:jl_generating_output, Cint, ()) == 1
636+
include("precompile.jl")
637+
end
638+
634639
end # module

src/precompile.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using PrecompileTools: @setup_workload, @compile_workload
2+
3+
@setup_workload begin
4+
# TODO: Are these all safe to call here and bake into the pkgimage?
5+
Connections.__init__()
6+
MultiPartParsing.__init__()
7+
Parsers.__init__()
8+
ConnectionRequest.__init__()
9+
10+
gzip_data(data::String) = read(GzipCompressorStream(IOBuffer(data)))
11+
12+
# random port in the dynamic/private range (49152–65535) which are are
13+
# least likely to be used by well-known services
14+
_port = 57813
15+
16+
server = HTTP.serve!("0.0.0.0", _port; verbose = -1) do req
17+
HTTP.Response(200, ["Content-Encoding" => "gzip"], gzip_data("dummy response"))
18+
end
19+
@compile_workload begin
20+
HTTP.get("http://localhost:$_port")
21+
end
22+
HTTP.forceclose(server)
23+
server = nothing
24+
end

0 commit comments

Comments
 (0)