Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a copy-paste invalidations analysis script #326

Merged
merged 10 commits into from
Jan 3, 2023
36 changes: 36 additions & 0 deletions docs/src/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,42 @@ Certain concepts and types will appear repeatedly, so it's worth
spending a little time to familiarize yourself at the outset.
You can find a more expansive version of this page in [this blog post](https://julialang.org/blog/2021/01/precompile_tutorial/).

## Cut to the Chase: A copy-paste analysis of invalidations

The following is a quick "grab and go" script for analyzing invalidations. Insert your code into the `@snoopr` block. The resulting plot shows the
distributions of the invalidations sorted by the number of children affected. Generally, invalidations with many children matter more than those
ChrisRackauckas marked this conversation as resolved.
Show resolved Hide resolved
with few children, and thus this shows how many "bad actors" need to be investigated. `show(trees[end])` show the method which leads to the most
invalidations, with `show(trees[end-1])` being the second most, and so forth.
ChrisRackauckas marked this conversation as resolved.
Show resolved Hide resolved

```julia
using SnoopCompileCore
invalidations = @snoopr using PkgA, PkgB;
using SnoopCompile
trees = invalidation_trees(invalidations)
tinf = @snoopi_deep begin
some_workload()
end
ChrisRackauckas marked this conversation as resolved.
Show resolved Hide resolved
staletrees = precompile_blockers(trees, tinf)

@show length(SnoopCompile.uinvalidated(invalidations)) # show total invalidations

show(trees[end]) # show the most invalidating method

# Count number of children (number of invalidations per invalidated method)
n_invalidations = map(trees) do methinvs
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I guess the question is, do we want to plot all invalidations or just the ones that affect the workload? I can go with this, I just worry it might seem daunting.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about plotting both next to each other?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or in different colors on the same axis.

SnoopCompile.countchildren(methinvs)
end
ChrisRackauckas marked this conversation as resolved.
Show resolved Hide resolved

import Plots
Plots.plot(
1:length(trees),
n_invalidations;
markershape=:circle,
xlabel="i-th method invalidation",
label="Number of children per method invalidations"
)
```

## `MethodInstance`s, type-inference, and backedges

Our first goal is to understand how code connects together.
Expand Down