Diary
module
s automatically contain using Core
, using Base
, and definitions of eval
and include
. If you only want Core
to be imported, you can use baremodule
instead. If you don’t even want Core
, you can do Module(:MyModuleName, false, false)
and Core.@eval
code into it (@eval MyModuleName add(x, y) = $(+)(x, y)
)julia --project
is the same as julia --project=.
MethodInstance
s, an internal type in Core.Compiler
Base.arrayref
in, e.g., @code_typed
is from boot.jl
Wait, arrayref
?
as of 1..11,
arrayref
is no longer a thing Julia knows about.Array
is basically a first classmutable struct
built on top ofMemory
. Initially we removedarrayref
entirely, but it turns out that enough people were using it (mostly for dumb reasons) that we added a fallback to prevent code from breaking
cf. #8
::Union{}
do not returnusing REPL; ModuleName <Alt+m>
: “Set mod as the default contextual module in the REPL, both for evaluating expressions and printing them.”@allocated
If you want to add custom diff rules for ForwardDiff.jl
, use ForwardDiffChainRules.jl to add a ForwardDiff dispatch for an already existing frule.
Details
Note that you can’t add rules toDiffRules
directly.
The reason is ForwardDiff
works by adding dispatches for the DiffRules
rules; to do that, it reads the DiffRules
tables containing all the rules. Doing, say, DiffRules.@define_diffrule
, adds the rules after they’ve been read by ForwardDiff
, so you get no dispatches for your custom rule.
You can also do something to add an additional dispatch of your function for values of type ForwardDiff.Dual
: myfunction(::ForwardDiff.Dual)
.
However, this is redundant and error-prone, while with ForwardDiffChainRules
you can re-use the differentiation code defined in an existing ChainRulesCore.frule
without having to re-code the diff rulesVSCode -> Settings (UI) -> Terminal > Integrated: Scrollback
for larger history buffer in REPLPkg.activate(; temp=true)
: Create and activate a temporary environment that will be deleted when the julia process is exitedUse TimerOutputs.jl
for profiling together with Revise
Example usage
|
|
|
|
Type
, Function
, Vararg
. You can add a type parameter to force specialization.
Cthulhu
, JET
(through @report_opt
) and @code_warntype
can get confused by this.
This can also be a reason StaticCompile
can fail due to dynamism while everything appears to be typestable.
#21 should catch these correctly.abstract
type
s with Abstract
, e.g. AbstractMyType
.
If its a parametric type, keep it as is (e.g. Base.Complex
instead of AbstractComplex
).
Be mindful of Ref
vs Refvalue
, too.Base.@nospecializeinfer
was added (but not advertized in any way) in Julia 1.10.
You can check what it does in the introducing PR.
An example of its use can be found in this JLD2 PR.
You can use SnoopCompile.@snoopi_deep
to figure out where to despecialize to cut down on time spent on time inference and make precompilation way more effective.precompile
only caches results for type-inference, not other stages in code generation.
For that reason, efforts at reducing latency should be informed by measuring the amount of time spent on type-inference.
You can do that using SnoopCompile.@snoopi_deep
.Argument standardization is a very important technique for reducing specilization: do foo(x::X, y::Y)
instead of foo(x, y)
.
Code
instead of
consider whether you can write it safely as
More
Part of the power of Julia is the ability to specify generic methods that “do the right thing” for a wide variety of types. However, when you’re doing a standard task, e.g., writing some data to a file, there’s no reason to recompile your “save
” method for a filename encoded as a String
, and again for a SubString{String}
, and for SubstitutionString
, and so on: if save
isn’t sensitive to the precise encoding of the filename, it should be safe to instead convert all filenams to String
, reducing the diversity of input arguments for expensive-to-compile methods.pgdsgui
for PGDS, aka, Profile-Guided DeSpecialization.ProfileCanvas
is great for profiling work either inside VSCode or a Pluto notebook.
There’s @profview
, but also @profview_allocs
to profile memory allocations.There are several reasons not to use higher order functions
More
- Julia sometimes doesn’t properly specialize higher order functions which can be hard to reason about
- It complicates stacktraces by adding more wrapper functions where no real business logic happens, and stacktraces with anonymous functions are especially harder to read
- It encourages closures, which are vulnerable to the slow closure bug which has proven very hard to fix
- The recursive inference issue
mapfoldl
/mapreduce
implementations have way too many layers.
It is very complicated, often slow, and often comes with inference problems.A way for finer grained control over what is considered to be API is speciliazing getproperty
.
Everything that is then accessible through getproperty
is considered to be API.
devdocs
: https://docs.julialang.org/en/v1.11-dev/devdocs/object/Pkg
mode without having to type ]
you can do julia -E'using Pkg; pkg"status"'
A few things that are on master now:
pkg> add --weak/--extra Foo
pkg> add
now adds compat entries for the added deps if the active env is a package- Julia now prefers reading
Manifest-v{major}.{minor}.toml
overManifest.toml
so you can have version specific manifests
OnlineStats
is amazingPartialStruct
intermediate types from @code_warntype
is about constant propagation.
It means the compiler knows that some values are guaranteed to be constant, but other parts of the struct
are notstruct
, but it’s more and more work for the compiler1.10-rc2
and get an error.
Remember, it needs to be in ~1.10.0-rc2
formTuple
/NamedTuple
.
If you use an abstractly-typed container like a Vector{Any}
, you’ll face performance hits due to the type instabilities introduced.IRCode
using your own AbstractInterpreter
and put it in an opaque closure.PersistentDict
starting from Julia 1.11.
Alternatively, you can also use a “Mutable until shared” discipline with MuttsDucts.jl
@latest
.
Make sure you read julia-actions/cache
docs to set it up well.JLD2.jl
, note that it caches loaded data by default.