Skip to content

Commit

Permalink
Remove SpeculationBenchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobjpeters committed Dec 27, 2024
1 parent 4556658 commit 7f62707
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 328 deletions.
2 changes: 0 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ version = "0.1.0"

[deps]
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

[compat]
InteractiveUtils = "1.10"
Serialization = "1.10.0"
julia = "1.10"
47 changes: 0 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,58 +55,11 @@ julia> i(::Union{String, Symbol}, ::Union{String, Symbol}) = nothing;
[ Info: Compiled `Main.i(::String, ::String)`
```

## Case Study

Consider [Plots.jl](https://github.com/JuliaPlots/Plots.jl), the go-to example when discussing
latency in Julia and the substantial improvements made to the time-to-first-X problem.

```julia-repl
julia> using Plots
julia> @elapsed plot(1)
0.106041791
```

This call has very low latency, demonstrating that code
for core functions has been effectively precompiled.
However, it is challenging to manually identify an exhaustive set of methods to precompile.
Speculator.jl can do this automatically.

```julia-repl
julia> @elapsed using Speculator
0.040658097
julia> SpeculationBenchmark(Plots)
Precompilation benchmark with `8` samples:
Mean: `5.1130`
Median: `5.1546`
Minimum: `4.7240`
Maximum: `5.5401`
```

The `SpeculationBenchmark` estimates the compilation time that `speculate` saves.
This case uses the minimum `target`, which only compiles methods of public
functions, types, and the types of values, recursively for public modules.
Although there are numerous additional targets, this target only precompiles a subset
of the methods that are accessible to users as part of the Plots.jl public interface.
This can be verified using `speculate(Plots; verbosity = debug | review)`.
Therefore, including this precompilation workload in Plots.jl or running it in the background
of an interactive session can save up to five seconds of compilation time per session.
Testing and selecting additional targets can save even more time.

If instead, the Plots.jl workload did not precompile any new methods,
using Speculator.jl would not meaningfully lengthen loading time.
The package itself takes a fraction of a second to load in a package or interactive session.
Running a workload in the background also only takes a fraction of a second to initiate.
Therefore, using Speculator.jl has a high benefit to
cost ratio in terms of compilation and loading time.

## Features

- Automatically generate a compilation workload from modules and callable objects.
- Configurable to run in the background, select precompilation targets, and write to a file.
- Can be ran in the REPL after each input.
- Benchmark the compilation time of a workload.

### Planned

Expand Down
47 changes: 0 additions & 47 deletions docs/source/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,58 +55,11 @@ julia> i(::Union{String, Symbol}, ::Union{String, Symbol}) = nothing;
[ Info: Compiled `Main.i(::String, ::String)`
```

## Case Study

Consider [Plots.jl](https://github.com/JuliaPlots/Plots.jl), the go-to example when discussing
latency in Julia and the substantial improvements made to the time-to-first-X problem.

```julia-repl
julia> using Plots
julia> @elapsed plot(1)
0.106041791
```

This call has very low latency, demonstrating that code
for core functions has been effectively precompiled.
However, it is challenging to manually identify an exhaustive set of methods to precompile.
Speculator.jl can do this automatically.

```julia-repl
julia> @elapsed using Speculator
0.040658097
julia> SpeculationBenchmark(Plots)
Precompilation benchmark with `8` samples:
Mean: `5.1130`
Median: `5.1546`
Minimum: `4.7240`
Maximum: `5.5401`
```

The `SpeculationBenchmark` estimates the compilation time that `speculate` saves.
This case uses the minimum `target`, which only compiles methods of public
functions, types, and the types of values, recursively for public modules.
Although there are numerous additional targets, this target only precompiles a subset
of the methods that are accessible to users as part of the Plots.jl public interface.
This can be verified using `speculate(Plots; verbosity = debug | review)`.
Therefore, including this precompilation workload in Plots.jl or running it in the background
of an interactive session can save up to five seconds of compilation time per session.
Testing and selecting additional targets can save even more time.

If instead, the Plots.jl workload did not precompile any new methods,
using Speculator.jl would not meaningfully lengthen loading time.
The package itself takes a fraction of a second to load in a package or interactive session.
Running a workload in the background also only takes a fraction of a second to initiate.
Therefore, using Speculator.jl has a high benefit to
cost ratio in terms of compilation and loading time.

## Features

- Automatically generate a compilation workload from modules and callable objects.
- Configurable to run in the background, select precompilation targets, and write to a file.
- Can be ran in the REPL after each input.
- Benchmark the compilation time of a workload.

### Planned

Expand Down
17 changes: 0 additions & 17 deletions scripts/trial_environment.jl

This file was deleted.

30 changes: 0 additions & 30 deletions scripts/trials.jl

This file was deleted.

13 changes: 5 additions & 8 deletions src/Speculator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,26 @@ TODO: wait for a background call to `speculate` to finish before starting anothe
TODO: document that some methods aren't skipped
`f(::String)`, `f(::Union{String, Symbol})`, `speculate(f; verbosity = debug)`
TODO: implement `Base.symdiff(::Verbosity, ::Verbosity...)`
TODO: remove dependency on InteractiveUtils.jl
=#

import Base:
eltype, firstindex, getindex, isdisjoint, isempty,
issetequal, issubset, iterate, lastindex, length, show
import Base: isdisjoint, isempty, issetequal, issubset, iterate, show
using Base:
Threads, IdSet, active_project, isdeprecated, issingletontype, isvarargtype,
loaded_modules_array, mul_with_overflow, specializations, uniontypes, unsorted_names
Threads, IdSet, isdeprecated, issingletontype, isvarargtype, loaded_modules_array,
mul_with_overflow, specializations, uniontypes, unsorted_names
using .Threads: @spawn
using Core: TypeofBottom, Typeof
using InteractiveUtils: subtypes
using Serialization: serialize

include("cartesian_products.jl")
include("all_modules.jl")
include("verbosities.jl")
include("utilities.jl")
include("speculation_benchmarks.jl")
include("speculate.jl")
include("input_speculators.jl")

export
AllModules, SpeculationBenchmark, Verbosity,
AllModules, Verbosity,
all_modules, debug, review, silent, warn, install_speculator, speculate, uninstall_speculator

speculate(Speculator; limit = 4)
Expand Down
112 changes: 0 additions & 112 deletions src/speculation_benchmarks.jl

This file was deleted.

5 changes: 2 additions & 3 deletions src/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ end

is_subset(f::Union{Int, UInt8}, _f::Union{Int32, UInt8}) = f == (f & _f)

function log_debug(p::Parameters, c::Counter, caller_type::Type, (@nospecialize caller_types))
function log_debug(p::Parameters, c::Counter, caller_type::Type, caller_types::Vector{Type})
p.counters[c] += 1

if debug p.verbosity
Expand Down Expand Up @@ -78,8 +78,7 @@ function round_time(x::Float64)
whole * '.' * rpad(fraction, 4, '0')
end

function signature(caller_type::Type, @nospecialize compilable_types)
@nospecialize
function signature(caller_type::Type, compilable_types::Vector{Type})
s = join(map(type -> "::" * string(type), compilable_types), ", ")
signature(caller_type) * '(' * s * ')'
end
Expand Down
Loading

0 comments on commit 7f62707

Please sign in to comment.