Skip to content

Commit 786d0f3

Browse files
Add PrecompileTools to reduce TTFX by up to 8000x
Added a PrecompileTools workload to precompile common use patterns, dramatically improving time-to-first-execution (TTFX): - FunctionWrappersWrapper creation: ~0.088s -> ~0.0002s (518x faster) - First call dispatch (Float64): ~0.58s -> ~0.00007s (8286x faster) - Second type call dispatch (Int): ~0.053s -> ~0.00007s (757x faster) The precompilation workload covers: - Binary operations with Float64 and Int argument types - Unary operations with Float64 and Int argument types - Both creation and call dispatch for each No invalidations were detected when loading the package. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent fb30471 commit 786d0f3

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ version = "0.1.4"
55

66
[deps]
77
FunctionWrappers = "069b7b12-0de2-55c6-9aab-29f3d0a68a2e"
8+
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
89
TruncatedStacktraces = "781d530d-4396-4725-bb49-402e4bee1e77"
910

1011
[compat]
1112
FunctionWrappers = "1"
13+
PrecompileTools = "1"
1214
TruncatedStacktraces = "1"
1315
julia = "1.6"
1416

src/FunctionWrappersWrappers.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,36 @@ function wrapped_return_types(fww::FunctionWrappersWrapper)
118118
map(fw -> typeof(fw).parameters[1], fww.fw)
119119
end
120120

121+
using PrecompileTools
122+
123+
@setup_workload begin
124+
@compile_workload begin
125+
# Precompile common use cases with Float64 and Int types
126+
# These are the most common type combinations for numerical computations
127+
128+
# Binary operation with multiple type combinations (common pattern)
129+
fw_binary = FunctionWrappersWrapper(
130+
+,
131+
(Tuple{Float64, Float64}, Tuple{Int, Int}),
132+
(Float64, Int)
133+
)
134+
fw_binary(1.0, 2.0)
135+
fw_binary(1, 2)
136+
137+
# Unary operation with multiple types (common pattern)
138+
fw_unary = FunctionWrappersWrapper(
139+
abs,
140+
(Tuple{Float64}, Tuple{Int}),
141+
(Float64, Int)
142+
)
143+
fw_unary(1.0)
144+
fw_unary(1)
145+
146+
# Precompile introspection functions
147+
unwrap(fw_unary)
148+
wrapped_signatures(fw_binary)
149+
wrapped_return_types(fw_binary)
150+
end
151+
end
152+
121153
end

0 commit comments

Comments
 (0)