latency: fix cat invalidations#216
latency: fix cat invalidations#216johnnychen94 wants to merge 6 commits intoJuliaLinearAlgebra:masterfrom
Conversation
This patch removes the invalidation on cat and thus reduces the OneHotArrays loading time from 4.5s to 0.5s (the normal status)
| else | ||
| throw(ArgumentError("dims keyword in cat of LinearMaps must be (1,2)")) | ||
| @static if VERSION >= v"1.8" | ||
| # Dispatching on `cat` makes compiler hard to infer types and causes invalidations |
There was a problem hiding this comment.
This is some random explaination; I figure this is related to the aggresive type inference introduced by JuliaLang/julia#45028 but I don't know what's actually happening behind the scene.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #216 +/- ##
==========================================
+ Coverage 99.30% 99.43% +0.12%
==========================================
Files 22 22
Lines 1591 1595 +4
==========================================
+ Hits 1580 1586 +6
+ Misses 11 9 -2 ☔ View full report in Codecov by Sentry. |
|
Looks like this isn't the right fix. I'll try to see if there's any better solution then. |
|
Interestingly, this seems to work well for Julia v1.10+. Unfortunately, load time of |
|
I like this, and I think we should push this even further: ride the generic call chain and catch somewhere much deeper, where there is almost no method competition. Doesn't work yet, but pushed to continue working on it from work tomorrow. |
This patch removes the invalidation on cat and thus reduces the OneHotArrays loading time from 4.5s to 0.5s (the normal status)
using OneHotArraysalone in a new Julia process needs about 0.57s. However,using LinearMapsbefore that makes the loading time of OneHotArrays to about 5s.With SnoopCompile I've noticed LinearMaps invalidates the
catmethods and OneHotArrays extends thecatmethods:This patch tweaks the
catmethod extension by dispatching on_catinstead ofcat, and somehow it does work:P.S. I figure this is related to JuliaLang/julia#45028 (because the
Core.kwcallhint in the invalidations list) but I don't know why this works. Maybe @aviatesk or @timholy knows the magic behind?Commenting out the
Base.catmethod in above link in OneHotArrays also reduces the latency, but I figure it's better to do it here since OneHotArrays looks more innocent while this packages code generates many cat methods in a seemingly wild way.FWIW, if we reduce the number
for k in 1:8to something likefor k in 1:4the latency won't be that severe, too. As an experiment:This makes
using OneHotArraystakes forever.