Skip to content

Commit a2e9d89

Browse files
JamesWrigleymkitti
andauthored
Update the docs to mention that native code is now cached (#377)
Co-authored-by: Mark Kittisopikul <[email protected]>
1 parent fb3f203 commit a2e9d89

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

docs/src/index.md

+18-17
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,24 @@ code generation performs optimizations and ultimately generates the assembly
2828
language (native code) used on CPUs.
2929
Some aspects of this process are documented [here](https://docs.julialang.org/en/v1/devdocs/eval/).
3030

31-
Every time you load a package in a fresh Julia session, the methods you use
32-
need to be JIT-compiled, and this contributes to the latency of using the package.
33-
In some circumstances, you can partially cache the results of compilation to a file
34-
(the `*.ji` files that live in your `~/.julia/compiled` directory) to reduce the burden
35-
when your package is used.
36-
This is called *precompilation*.
37-
Unfortunately, precompilation is not as comprehensive as one might hope.
38-
Currently, Julia is only able to save inference results (not native code) in the
39-
`*.ji` files, and thus precompilation only eliminates the time needed for type inference.
40-
Moreover, there are some significant constraints that sometimes prevent Julia from
41-
saving even the inference results--for example, currently you cannot cache inference results
42-
for "top level" calls to methods defined in Julia or other packages, even if you are calling them
43-
with types defined in your package.
44-
Finally, what does get saved can sometimes be invalidated by loading other packages.
45-
46-
Despite these limitations, there are many cases where precompilation can substantially reduce
47-
latency.
31+
Every time you load a package in a fresh Julia session, the methods you use need
32+
to be JIT-compiled, and this contributes to the latency of using the package.
33+
In some circumstances, you can cache the results of compilation to files to
34+
reduce the latency when your package is used. These files are the the `*.ji` and
35+
`*.so` files that live in the `compiled` directory of the Julia depot, usually
36+
located at `~/.julia/compiled`. However, if these files become large, loading
37+
them can be another source for latency. Julia needs time both to load and
38+
validate the cached compiled code. Minimizing the latency of using a package
39+
involves focusing on caching the compilation of code that is both commonly used
40+
and takes time to compile.
41+
42+
This is called *precompilation*. Julia is able to save inference results in the
43+
`*.ji` files and ([since Julia
44+
1.9](https://julialang.org/blog/2023/04/julia-1.9-highlights/#caching_of_native_code))
45+
native code in the `*.so` files, and thus precompilation can eliminate the time
46+
needed for type inference and native code compilation (though what does get
47+
saved can sometimes be invalidated by loading other packages).
48+
4849
SnoopCompile is designed to try to allow you to analyze the costs of JIT-compilation, identify
4950
key bottlenecks that contribute to latency, and set up `precompile` directives to see whether
5051
it produces measurable benefits.

docs/src/snoopc.md

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
`@snoopc` has the advantage of working on any modern version of Julia.
44
It "snoops" on the code-generation phase of compilation (the 'c' is a reference to
55
code-generation).
6-
Note that while native code is not cached, it nevertheless reveals
7-
which methods are being compiled.
86

97
Note that unlike `@snoopi`, `@snoopc` will generate all methods, not just the top-level
108
methods that trigger compilation.

0 commit comments

Comments
 (0)