perf: avoid test_inverse import-time compilation#62
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #62 +/- ##
==========================================
+ Coverage 98.48% 98.49% +0.01%
==========================================
Files 6 6
Lines 132 133 +1
==========================================
+ Hits 130 131 +1
Misses 2 2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
8bc2d9c to
70c8b41
Compare
| function test_inverse(args...; kwargs...) | ||
| throw(ArgumentError("InverseFunctions.test_inverse requires the Test standard library. Did you forget to load Test?")) | ||
| end |
There was a problem hiding this comment.
This changes the behaviour: Currently, the error hint with the question is only shown when the extension is actually not loaded. This message here will instead be displayed unconditionally, and users will see an ArgumentError with an incorrect message instead of eg a MethodError.
There was a problem hiding this comment.
Good catch. I changed this so the fallback no longer changes unrelated call errors.
The fallback is still a varargs method so the Test extension can add its real test_inverse(f, x; ...) method without overwriting during precompilation. But it now only emits the friendly missing-Test message for the normal two-argument call. Other signatures throw MethodError, matching existing behavior better.
There was a problem hiding this comment.
No, even the behaviour of the new version is different from master. There's no point in asking the user to load the extension if it's already loaded.
There was a problem hiding this comment.
If test is already loaded, the ArgumentError would never be throwed I think.
Since Julia owns MethodError display so to improve load-time compilation,
options are :
- Exact old exception behavior, faster load: MethodError, but no “Did you forget…” hint.
- Or friendly message, changed exception: define fallback method, throw ArgumentError / ErrorException.
I felt like keeping original UX with longer load-time is worse as this function is rarely used downstream and require Test to load first to use it anyway.
70c8b41 to
441dcba
Compare
Summary
Small load-time cleanup: replace the runtime
__init__error hint with a directtest_inversefallback method. Users still get a friendly error whenTestis missing, but package import no longer pays for the error-hint hook.Benchmark
Measured with
julia --startup-file=no --project=@. -e 'using InteractiveUtils; @time_imports using InverseFunctions'after precompile.74.2 ms InverseFunctions,98.73% compilation time0.7 ms InverseFunctions