Skip to content

Commit 9f9c1db

Browse files
jakobnissenquinnj
andauthored
Add SnoopPrecompile (#228)
The small dependency SnoopPrecompile helps precompilation, while itself having little impact on latency. With this change, JSON3 precompiles significantly better. Co-authored-by: Jacob Quinn <[email protected]>
1 parent 3bac427 commit 9f9c1db

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ version = "1.10.0"
77
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
88
Mmap = "a63ad114-7e13-5084-954f-fe012c677804"
99
Parsers = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
10+
SnoopPrecompile = "66db9d55-30c0-4569-8b51-7e840670fc0c"
1011
StructTypes = "856f2bd8-1eba-4b0a-8007-ebc267875bd4"
1112
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
1213

1314
[compat]
1415
Parsers = "0.3, 1, 2"
1516
StructTypes = "1.10"
1617
julia = "1.6"
18+
SnoopPrecompile = "1"
1719

1820
[extras]
1921
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

src/JSON3.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,6 @@ include("write.jl")
172172
include("pretty.jl")
173173
include("gentypes.jl")
174174

175+
include("workload.jl")
176+
175177
end # module

src/workload.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using SnoopPrecompile
2+
3+
@precompile_all_calls begin
4+
str = """{"a": 1, "b": "hello, world", "c": [1, 2], "d": true, "e": null, "f": 1.92}"""
5+
6+
JSON3.read(IOBuffer(str))
7+
json = JSON3.read(str)
8+
for i in "abcdef"
9+
json[i]
10+
end
11+
12+
JSON3.read(
13+
str,
14+
NamedTuple{(:a, :b, :c, :d, :e, :f), Tuple{Int, String, Vector{Int}, Bool, Nothing, Float32}}
15+
)
16+
17+
JSON3.write(IOBuffer(), json)
18+
JSON3.pretty(IOBuffer(), json)
19+
end

0 commit comments

Comments
 (0)