execution: add compilation=true mode for benchmarking compile time#421
Draft
IanButterworth wants to merge 1 commit intomainfrom
Draft
execution: add compilation=true mode for benchmarking compile time#421IanButterworth wants to merge 1 commit intomainfrom
IanButterworth wants to merge 1 commit intomainfrom
Conversation
| # invalidation caps the CodeInstance but does not | ||
| # propagate to backedges (that would defeat the purpose), | ||
| # so a devirtualized call would keep using the stale fptr. | ||
| __arg_types = Tuple{$([:(Core.Typeof($v)) for v in [quote_vars; setup_vars]]...)} |
Contributor
There was a problem hiding this comment.
[JuliaFormatter] reported by reviewdog 🐶
Suggested change
| __arg_types = Tuple{$([:(Core.Typeof($v)) for v in [quote_vars; setup_vars]]...)} | |
| __arg_types = Tuple{ | |
| $([:(Core.Typeof($v)) for v in [quote_vars; setup_vars]]...) | |
| } |
| end | ||
|
|
||
| const DEFAULT_PARAMETERS = Parameters(5.0, 10000, 1, false, 0, true, false, 0.05, 0.01) | ||
| const DEFAULT_PARAMETERS = Parameters(5.0, 10000, 1, false, 0, true, false, 0.05, 0.01, false) |
Contributor
There was a problem hiding this comment.
[JuliaFormatter] reported by reviewdog 🐶
Suggested change
| const DEFAULT_PARAMETERS = Parameters(5.0, 10000, 1, false, 0, true, false, 0.05, 0.01, false) | |
| const DEFAULT_PARAMETERS = Parameters( | |
| 5.0, 10000, 1, false, 0, true, false, 0.05, 0.01, false | |
| ) |
| end | ||
|
|
||
| Trial(params::Parameters) = Trial(params, Float64[], Float64[], typemax(Int), typemax(Int)) | ||
| Trial(params::Parameters) = Trial(params, Float64[], Float64[], Float64[], typemax(Int), typemax(Int)) |
Contributor
There was a problem hiding this comment.
[JuliaFormatter] reported by reviewdog 🐶
Suggested change
| Trial(params::Parameters) = Trial(params, Float64[], Float64[], Float64[], typemax(Int), typemax(Int)) | |
| function Trial(params::Parameters) | |
| return Trial(params, Float64[], Float64[], Float64[], typemax(Int), typemax(Int)) | |
| end |
Comment on lines
+17
to
+18
| Trial(params::Parameters, times::AbstractVector, gctimes::AbstractVector, memory::Integer, allocs::Integer) = | ||
| Trial(params, times, gctimes, zeros(Float64, length(times)), memory, allocs) |
Contributor
There was a problem hiding this comment.
[JuliaFormatter] reported by reviewdog 🐶
Suggested change
| Trial(params::Parameters, times::AbstractVector, gctimes::AbstractVector, memory::Integer, allocs::Integer) = | |
| Trial(params, times, gctimes, zeros(Float64, length(times)), memory, allocs) | |
| function Trial( | |
| params::Parameters, | |
| times::AbstractVector, | |
| gctimes::AbstractVector, | |
| memory::Integer, | |
| allocs::Integer, | |
| ) | |
| return Trial(params, times, gctimes, zeros(Float64, length(times)), memory, allocs) | |
| end |
|
|
||
| function Base.copy(t::Trial) | ||
| return Trial(copy(t.params), copy(t.times), copy(t.gctimes), t.memory, t.allocs) | ||
| return Trial(copy(t.params), copy(t.times), copy(t.gctimes), copy(t.compiletimes), t.memory, t.allocs) |
Contributor
There was a problem hiding this comment.
[JuliaFormatter] reported by reviewdog 🐶
Suggested change
| return Trial(copy(t.params), copy(t.times), copy(t.gctimes), copy(t.compiletimes), t.memory, t.allocs) | |
| return Trial( | |
| copy(t.params), | |
| copy(t.times), | |
| copy(t.gctimes), | |
| copy(t.compiletimes), | |
| t.memory, | |
| t.allocs, | |
| ) |
| Base.length(t::Trial) = length(t.times) | ||
| function Base.getindex(t::Trial, i::Number) | ||
| return push!(Trial(t.params), t.times[i], t.gctimes[i], t.memory, t.allocs) | ||
| return push!(Trial(t.params), t.times[i], t.gctimes[i], t.memory, t.allocs, t.compiletimes[i]) |
Contributor
There was a problem hiding this comment.
[JuliaFormatter] reported by reviewdog 🐶
Suggested change
| return push!(Trial(t.params), t.times[i], t.gctimes[i], t.memory, t.allocs, t.compiletimes[i]) | |
| return push!( | |
| Trial(t.params), t.times[i], t.gctimes[i], t.memory, t.allocs, t.compiletimes[i] | |
| ) | |
| end | |
| function Base.getindex(t::Trial, i) | |
| return Trial(t.params, t.times[i], t.gctimes[i], t.compiletimes[i], t.memory, t.allocs) |
| return push!(Trial(t.params), t.times[i], t.gctimes[i], t.memory, t.allocs, t.compiletimes[i]) | ||
| end | ||
| Base.getindex(t::Trial, i) = Trial(t.params, t.times[i], t.gctimes[i], t.memory, t.allocs) | ||
| Base.getindex(t::Trial, i) = Trial(t.params, t.times[i], t.gctimes[i], t.compiletimes[i], t.memory, t.allocs) |
Contributor
There was a problem hiding this comment.
[JuliaFormatter] reported by reviewdog 🐶
Suggested change
| Base.getindex(t::Trial, i) = Trial(t.params, t.times[i], t.gctimes[i], t.compiletimes[i], t.memory, t.allocs) |
| compile_bench_target(x) = sum(abs2, x) + prod(x .+ one(eltype(x))) | ||
| # Warm up to ensure we exercise the already-compiled path. | ||
| compile_bench_target(rand(8)) | ||
| let t = @benchmark compile_bench_target($(rand(8))) samples=5 seconds=30 compilation=true evals=1 |
Contributor
There was a problem hiding this comment.
[JuliaFormatter] reported by reviewdog 🐶
Suggested change
| let t = @benchmark compile_bench_target($(rand(8))) samples=5 seconds=30 compilation=true evals=1 | |
| let t = @benchmark compile_bench_target($(rand(8))) samples = 5 seconds = 30 compilation = | |
| true evals = 1 |
Add a `compilation::Bool` parameter to `Parameters` that, when enabled, invalidates the target call's entry-point `MethodInstance` between samples and records the resulting compile time via `Base.cumulative_compile_time_ns`. Each `Trial` now carries a `compiletimes` vector alongside `times`/`gctimes`, accessible via `compiletime(t)`, with compile stats rendered in the `show` output. Samples dispatch through `Base.invokelatest` so the direct call site baked into the generated `samplefunc` is bypassed — `invalidate_calls` caps the `CodeInstance`'s `max_world` but does not propagate to backedges, so a devirtualized call would otherwise keep using the stale fptr. `evals` is forced to 1 in this mode since repeated evaluations would amortize compilation away. Relies on `Base.record_calls` / `Base.invalidate_calls` landing in Julia; guarded via `isdefined(Base, :invalidate_calls)` in the tests. Co-Authored-By: Claude <noreply@anthropic.com>
78bb3ef to
4975433
Compare
| __gcdiff.bigalloc, | ||
| ) | ||
| __compiletime = __stats.compile_time * 1e9 | ||
| __sample_ref[] = (__time, __gctime, __memory, __allocs, __compiletime) |
Contributor
There was a problem hiding this comment.
[JuliaFormatter] reported by reviewdog 🐶
Suggested change
| __sample_ref[] = (__time, __gctime, __memory, __allocs, __compiletime) | |
| __sample_ref[] = ( | |
| __time, __gctime, __memory, __allocs, __compiletime | |
| ) |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Developed with Claude. Functional but not closely reviewed yet.
Requires JuliaLang/julia@4c7c3e9
Add a
compilation::Boolparameter toParametersthat, when enabled, invalidates the target call's entry-pointMethodInstancebetween samples and records the resulting compile time viaBase.cumulative_compile_time_ns. EachTrialnow carries acompiletimesvector alongsidetimes/gctimes, accessible viacompiletime(t), with compile stats rendered in theshowoutput.Samples dispatch through
Base.invokelatestso the direct call site baked into the generatedsamplefuncis bypassed —invalidate_callscaps theCodeInstance'smax_worldbut does not propagate to backedges, so a devirtualized call would otherwise keep using the stale fptr.evalsis forced to 1 in this mode since repeated evaluations would amortize compilation away.Relies on
Base.record_calls/Base.invalidate_callslanding in Julia; guarded viaisdefined(Base, :invalidate_calls)in the tests.