Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions doc/src/manual/performance-tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,29 @@
when argument types are changed, i.e., if `Base.specializations(@which f(...))` contains specializations
for the argument in question.

Note that in the presence of keywords and optional positional arguments, you may need to force specialization of a method argument
even though the method is called in the body. This is due to how Julia rewrites method with default arguments. If we consider:

```julia
g(f, x=1) = f(...)
```

the method argument `f` is here clearly used within the method `g`. However, julia will rewrite this as:

```julia
g(f, x) = f(...)
g(f) = g(f, 1)
```

With this rewrite, the second method that passes along the default argument value does no longer use `f`, calling `g(f)` may therefore not specialize on `f`.
Writing the original definition as

```julia
g(f::F, x=1) where {F} = f(...)
```

woudld solve this.

Check warning on line 676 in doc/src/manual/performance-tips.md

View workflow job for this annotation

GitHub Actions / Check for new typos

perhaps "woudld" should be "would".

### Write "type-stable" functions

When possible, it helps to ensure that a function always returns a value of the same type. Consider
Expand Down