Created
February 10, 2022 15:50
-
-
Save timholy/016e44d0356510a9de0ee67b39fed9c2 to your computer and use it in GitHub Desktop.
Demo package & commands for native-code caching
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
module CacheNative | |
using Random | |
const somearray = [1,2,3] | |
struct SomeType | |
str::String | |
end | |
# @noinline ensures these are compiled as stand-alone functions | |
@noinline function greet(io::IO) | |
print(io, "Hello World! sin of a random number is ") | |
print(io, sin(rand())) | |
end | |
@noinline usesconst() = somearray[2] | |
@noinline usestype(dest) = push!(dest, SomeType(randstring())) | |
@noinline uncompiled(io::IO) = print(io, "Too shy to compile") | |
# Precompilation | |
let io = IOBuffer() | |
Base.Experimental.@force_compile | |
greet(io) | |
println(usesconst()) | |
usestype(SomeType[]) | |
end | |
end # module |
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
concrete_deps = copy(Base._concrete_dependencies) | |
for (key, mod) in Base.loaded_modules | |
if !(mod === Main || mod === Core || mod === Base) | |
push!(concrete_deps, key => Base.module_build_id(mod)) | |
end | |
end | |
using UUIDs | |
id = Base.PkgId(UUID("7b64b5d0-837b-40ad-8851-c89c95834730"), "CacheNative") | |
Base.include_package_for_output(id, "/home/tim/tmp/caching_native/CacheNative/src/CacheNative.jl", ["/home/tim/.julia", "/home/tim/src/julia-master/usr/local/share/julia", "/home/tim/src/julia-master/usr/share/julia"], String[], ["/home/tim/tmp/caching_native/CacheNative/Project.toml", "/home/tim/.julia/environments/v1.8/Project.toml", "/home/tim/src/julia-master/usr/share/julia/stdlib/v1.8"], concrete_deps, nothing) |
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
name = "CacheNative" | |
uuid = "7b64b5d0-837b-40ad-8851-c89c95834730" | |
authors = ["Tim Holy <[email protected]>"] | |
version = "0.1.0" | |
[deps] | |
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment