generated from quinnj/Example.jl
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hack to avoid inference recursion limit (#15)
* add a hack to avoid inference recursion limit to allow more optimization For this target: ```julia using JSONBase, BenchmarkTools struct A a::Int b::Int c::Int d::Int end @benchmark JSONBase.materialize("""{ "a": 1, "b": 2, "c": 3, "d": 4}""", A) ``` Before: ```julia BenchmarkTools.Trial: 10000 samples with 331 evaluations. Range (min … max): 258.937 ns … 4.373 μs ┊ GC (min … max): 0.00% … 91.32% Time (median): 279.202 ns ┊ GC (median): 0.00% Time (mean ± σ): 291.054 ns ± 185.340 ns ┊ GC (mean ± σ): 3.24% ± 4.74% ▃█▃ ▂ ▁▂▂▂▁▁▁▁▃███▃▂▂▄█▇▅▅▅▄▂▂▂▃▃▄▃▂▂▂▂▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▂ 259 ns Histogram: frequency by time 334 ns < Memory estimate: 384 bytes, allocs estimate: 10. ``` After: ```julia BenchmarkTools.Trial: 10000 samples with 750 evaluations. Range (min … max): 173.333 ns … 1.618 μs ┊ GC (min … max): 0.00% … 86.43% Time (median): 179.389 ns ┊ GC (median): 0.00% Time (mean ± σ): 184.518 ns ± 58.847 ns ┊ GC (mean ± σ): 1.40% ± 3.86% ▂▄▆██▇▅▄▁▁ ▂▃▄▅▄▄▄▄▂▁▁▁▂▂▂▂▂▂▂▂▂▂▁ ▂ ▂▅▄▅▅▃▃█████████████████████████████████████████████▇▇▅▄▅▆▅▅ █ 173 ns Histogram: log(frequency) by time 200 ns < Memory estimate: 128 bytes, allocs estimate: 2. ``` closes #2 * Rebase/update PR * fix 32-bit * fix 32-bit more --------- Co-authored-by: Shuhei Kadowaki <aviatesk@gmail.com>
- Loading branch information
Showing
10 changed files
with
126 additions
and
12 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module test_optimization | ||
|
||
using JSONBase, JET | ||
|
||
struct OptimizationFailureChecker end | ||
function JET.configured_reports(::OptimizationFailureChecker, reports::Vector{JET.InferenceErrorReport}) | ||
return filter(reports) do @nospecialize report::JET.InferenceErrorReport | ||
isa(report, JET.OptimizationFailureReport) | ||
end | ||
end | ||
|
||
# https://github.com/quinnj/JSONBase.jl/issues/2 | ||
struct Simple | ||
a::Int | ||
b::Int | ||
end | ||
@test_opt annotate_types=true report_config=OptimizationFailureChecker() JSONBase.materialize("""{ "a": 1, "b": 2 }""", Simple) | ||
|
||
struct Inner | ||
b::Int | ||
end | ||
struct Outer | ||
a::Int | ||
b::Inner | ||
end | ||
@test_opt annotate_types=true report_config=OptimizationFailureChecker() JSONBase.materialize("""{ "a": 1, "b": { "b": 2 } }""", Outer) | ||
|
||
struct SelfRecur | ||
a1::Int | ||
a2::Union{Nothing,SelfRecur} | ||
end | ||
@test_opt annotate_types=true report_config=OptimizationFailureChecker() JSONBase.materialize("""{ "a1": 1, "a2": { "a1": 2 } }""", SelfRecur) | ||
|
||
struct RecurInner{T} | ||
a::T | ||
end | ||
struct RecurOuter | ||
a1::Int | ||
a2::Union{Nothing,RecurInner{RecurOuter}} | ||
end | ||
@test_opt annotate_types=true report_config=OptimizationFailureChecker() JSONBase.materialize("""{ "a1": 1, "a2": { "a": { "a1": 2 } } }""", RecurOuter) | ||
|
||
end # module test_optimization |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters