Draft
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #887 +/- ##
==========================================
+ Coverage 95.60% 95.63% +0.03%
==========================================
Files 38 38
Lines 3708 3737 +29
==========================================
+ Hits 3545 3574 +29
Misses 163 163
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…MixedModels.jl into pa/reworked-fitted-predicted
…eworked-fitted-predicted
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With the help of ChatGPT,1 I managed to reduce a few allocations in
fitted/predict. One aspect builds on some comments we already had in the code about having aneffects!helper to reduce some duplicate computations. The other aspect restructurespredict(newdata)so that it only allocates the actual model matrices and not A and L (and theoptsum, but the impact of that is really quite trivial).The changes focus on two areas:
fitted!LinearMixedModelinsidepredict(newdata)when only prediction design matrices are neededHere's how ChatGPT summarized the changes:
Code Changes
fitted!/ internal effects pathfitted!(v, m)through explicit internalβ/bworkspacesfixef,coef, andranefbehavior unchangedpredict(newdata):errorbranch with the same sorted-term ordering used elsewhere in predictionLinearMixedModel(f, newdata; ...)construction with a lightweight prediction-design path that only builds the fixed-effects and random-effects design terms needed for predictionBenchmarks / docs
benchmark/fitted_predict.jlfor dataset/formula-drivenfitted/predictbenchmarkingbenchmark/compare_fitted_predict.jlfor comparing two checkouts/worktreesbenchmark/README.mddocumenting the benchmark scriptsBenchmark Results
Compared against pre-series baseline commit #87138de3.
sleepstudyfitted!(buf, m): 2144 B -> 1520 B, 4.57 µs -> 4.24 µsfitted(m): 3952 B -> 3216 B, 5.24 µs -> 4.95 µspredict(m, same_data): 111704 B -> 94656 B, 105.0 µs -> 89.9 µspredict(m, new_levels; new_re_levels=:population): 104840 B -> 82576 B, 96.7 µs -> 94.2 µskb07fitted!(buf, m): 4032 B -> 2864 B, 16.49 µs -> 15.65 µsfitted(m): 18816 B -> 17456 B, 18.12 µs -> 16.86 µspredict(m, same_data): 1391448 B -> 1292224 B, 874.9 µs -> 722.2 µspredict(m, new_subject; new_re_levels=:population): 1331104 B -> 1161840 B, 798.5 µs -> 715.8 µsdocs/NEWS-update.jlto update the cross-references.Footnotes
The impetus for this was a curiosity about how LLMs would perform with a large, complex codebase in a somewhat uncommon language that used some math that is, unfortunately, not as well known as it should be. So I basically asked it to audit the codebase for potential bugs and it found a few small things and suggested optimizing the allocation behavior here. I was aware of how inefficient the behavior was, but probably would have never gotten around to improving it because it's good enough for the cases I've personally encountered. ↩