Skip to content

Commit 6aa6981

Browse files
add an offline precompile workload (#1195)
* add an offline precompile workload * suggestions * fix * tweak inits * precompile https * only run workload if precompiling pkgimages * Update src/precompile.jl * Revert "Update src/precompile.jl" This reverts commit cb9b1f2. * precompile wheter or not pkgimages are used --------- Co-authored-by: Jacob Quinn <[email protected]>
1 parent f44242e commit 6aa6981

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

Project.toml

+3-1
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

+5
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 VERSION >= v"1.9.0-0" && ccall(:jl_generating_output, Cint, ()) == 1
636+
include("precompile.jl")
637+
end
638+
634639
end # module

src/precompile.jl

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using PrecompileTools: @setup_workload, @compile_workload
2+
3+
@setup_workload begin
4+
# These need to be safe to call here and bake into the pkgimage, i.e. called twice.
5+
Connections.__init__()
6+
MultiPartParsing.__init__()
7+
Parsers.__init__()
8+
9+
# Doesn't seem to be needed here, and might not be safe to call twice (here and during runtime)
10+
# ConnectionRequest.__init__()
11+
12+
gzip_data(data::String) = read(GzipCompressorStream(IOBuffer(data)))
13+
14+
# random port in the dynamic/private range (49152–65535) which are are
15+
# least likely to be used by well-known services
16+
_port = 57813
17+
18+
cert, key = joinpath.(@__DIR__, "../test", "resources", ("cert.pem", "key.pem"))
19+
sslconfig = MbedTLS.SSLConfig(cert, key)
20+
21+
server = HTTP.serve!("0.0.0.0", _port; verbose = -1, listenany=true, sslconfig=sslconfig) do req
22+
HTTP.Response(200, ["Content-Encoding" => "gzip"], gzip_data("dummy response"))
23+
end
24+
# listenany allows changing port if that one is already in use, so check the actual port
25+
_port = HTTP.port(server)
26+
url = "https://localhost:$_port"
27+
28+
env = ["JULIA_NO_VERIFY_HOSTS" => "localhost",
29+
"JULIA_SSL_NO_VERIFY_HOSTS" => nothing,
30+
"JULIA_ALWAYS_VERIFY_HOSTS" => nothing]
31+
withenv(env...) do
32+
@compile_workload begin
33+
HTTP.get(url);
34+
end
35+
end
36+
37+
HTTP.forceclose(server)
38+
server = nothing
39+
end

0 commit comments

Comments
 (0)