-
Notifications
You must be signed in to change notification settings - Fork 42
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
latency: fix cat invalidations #216
base: master
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 OneHotArrays
alone in a new Julia process needs about 0.57s. However,using LinearMaps
before that makes the loading time of OneHotArrays to about 5s.With SnoopCompile I've noticed LinearMaps invalidates the
cat
methods and OneHotArrays extends thecat
methods:This patch tweaks the
cat
method extension by dispatching on_cat
instead ofcat
, and somehow it does work:P.S. I figure this is related to JuliaLang/julia#45028 (because the
Core.kwcall
hint in the invalidations list) but I don't know why this works. Maybe @aviatesk or @timholy knows the magic behind?Commenting out the
Base.cat
method 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:8
to something likefor k in 1:4
the latency won't be that severe, too. As an experiment:This makes
using OneHotArrays
takes forever.