agentleFS
90184479018447/julia-pro-p/skills/performance-tuning/SKILL.md

performance-tuning

Skill0 starsChanged 2 days agoMITView on GitHub

Make Julia code faster without lying: measure with @time and @btime, find type instability and allocation, change one thing, prove the delta from fresh processes. Use when a Julia program is slow or a speedup is claimed.

11 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use writing-skills, test-driven-development and 1 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • OpenAISkill

    writing-skills

    Use when creating new skills, editing existing skills, or verifying skills work before deployment

    Also in 3 projects that use this

  • OpenAISkill

    test-driven-development

    Use when implementing any feature or bugfix, before writing implementation code

    Also in 3 projects that use this

  • GoogleSkill

    code-review

    Adversarial systems, concurrency, memory-model, and architecture code review protocol. Use this skill whenever asked to review code, PRs, diffs, or branches in Filament.

    Also in 5 projects that use this

The file

We split this skill into the rules it gives an agent

2 rules. 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 8 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Run each three times: the first call is compilation, the second may hit a different method instance, the third is steady state.

    line 21
  2. Distinctive:

    When the answer is "it depends on input", give the crossover point — the size at which the lever flips.

    line 45

“Common” is measured: kept by at least 6 in 10 of the 8 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Performance tuning

Julia's cost model has three clocks, and a change usually trades one for another: compile time to first result, steady-state runtime per call, and the memory traffic that decides whether the other two hold under load.

principle-three-clocks is the judgement; this file is the levers.

Measure before choosing a lever

@time f(x)                     # includes compilation on the first call
@btime f($x)                   # BenchmarkTools: steady state, no compilation noise
@allocated f(x)                 # bytes per call; the number most fixes move
@code_warntype f(x)             # red = non-concrete type reaching a branch

Run each three times: the first call is compilation, the second may hit a different method instance, the third is steady state. Report which clock you measured — a "10× faster" claim that only moved compile time is a claim about the wrong clock.

Symptom to lever

SymptomLeverCheck
@code_warntype shows Any/Uniona function barrier, or a type annotation on the container, not on the argument@inferred f(x)
allocations on the hot pathpreallocate and mutate in place; @views; setindex!@allocated drops to the output only
a closure captures a reassigned variablea let block, or pass the value as an argument@code_lowered shows the box
seconds on the first calla precompile workload (PrecompileTools.@compile_workload)--startup-file=no timing
slow before main runsSnoopCompile for invalidationsSnoopCompile.report_invalidations()
one core busyThreads.@threads, then @spawn for uneven workThreads.nthreads() > 1 and per-thread timing
memory-bound, not compute-bound@simd, LoopVectorization.@turbo, alignment--code-coverage=none; loop order
GC pauses dominateavoid boxing in a loop; --heap-size-hintGC.gc_time share of wall time

A function barrier is the lever most often missed: the outer function may be type-unstable, but the inner one, called once per element with concrete arguments, still specialises — and that is where the time goes.

Prove the delta

A speedup is a before/after pair measured the same way, on the same machine, in the same process shape.

  1. Record the baseline in the repo — benchmarks/ with a committed reference — so the next change has something to regress against.
  2. Measure after with the identical command; report both numbers and the ratio.
  3. State the clock: compile, steady state, or memory. A change that helps steady state and hurts compile time is not "faster" without that sentence.
  4. When the answer is "it depends on input", give the crossover point — the size at which the lever flips.

Depth

  • references/profiling-julia-performance.md — Profile.jl, allocation profiling, flame graphs.
  • references/precompiling-julia-package.md — PrecompileTools, sysimages.
  • references/compiler-patterns.md — PackageCompiler.jl, SnoopCompile, shipping.
  • ../differentiation/SKILL.md — the AD choice as a performance decision, and its cost.
  • references/julia-hpc-distributed.md — threads, Distributed.jl, MPI.
  • references/julia-gpu-kernels.md — CUDA.jl, kernel-level work.

Done when

There is a measured baseline from a benchmark that reports its own variance (BenchmarkTools), one lever was changed, and the delta is larger than that variance on the same machine; the profile that motivated the lever is kept, since it is what makes the next reader believe the number.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.