Commit 2ead553
committed
Avoid unnecessary keyword arguments check in fallback rrule
The expansion `rrule(::Any, ::Vararg{Any}; kwargs...)` actually
generates two methods. One along the lines of:
```
(::typeof(Core.kwfunc(rrule))(kwargs, ::typeof(rrule), ::Any, ::Vararg{Any}) = nothing
```
and the other that just calls it:
```
rrule(a::Any, b::Vararg{Any}) = Core.kwfunc(rrule)(NamedTuple{}(), a, b...)
```
The compiler handles this fallback well, since it's used all over the place,
but the cost to infer it is non-zero. Of course, in the AD use case, this
fallback method is visited literally on every call, so saving a tiny amount
of inference/compile time actually leads to noticable improvements over
a whole AD problem.1 parent 01b956f commit 2ead553
2 files changed
+34
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
2 | 4 | | |
3 | 5 | | |
| |||
198 | 200 | | |
199 | 201 | | |
200 | 202 | | |
201 | | - | |
| 203 | + | |
202 | 204 | | |
203 | 205 | | |
204 | 206 | | |
| |||
307 | 309 | | |
308 | 310 | | |
309 | 311 | | |
310 | | - | |
| 312 | + | |
311 | 313 | | |
312 | 314 | | |
313 | 315 | | |
314 | | - | |
| 316 | + | |
315 | 317 | | |
316 | 318 | | |
317 | 319 | | |
| |||
320 | 322 | | |
321 | 323 | | |
322 | 324 | | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
323 | 332 | | |
324 | 333 | | |
325 | 334 | | |
326 | 335 | | |
327 | | - | |
| 336 | + | |
328 | 337 | | |
329 | 338 | | |
330 | 339 | | |
| |||
349 | 358 | | |
350 | 359 | | |
351 | 360 | | |
352 | | - | |
353 | | - | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
354 | 368 | | |
355 | 369 | | |
356 | | - | |
| 370 | + | |
357 | 371 | | |
358 | 372 | | |
359 | 373 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
0 commit comments