perf(ensemble): pre-allocate tree and sample vector capacities in forest models#386
Conversation
…nd regressors Signed-off-by: Aditya <adityadahale96@gmail.com>
|
thanks! did you run some profiling and benching to see if the new code is faster/slower? it would be nice to know. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## development #386 +/- ##
===============================================
- Coverage 45.59% 44.36% -1.24%
===============================================
Files 93 95 +2
Lines 8034 8070 +36
===============================================
- Hits 3663 3580 -83
- Misses 4371 4490 +119 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Code ReviewThanks for the PR @Aditya-9-6! This is a clean, focused, and correct performance improvement. Here's a summary of the review: ✅ Strengths
|
|
Thanks for the thorough review @Mec-iS!
All CI linting checks and unit tests are passing clean! |
|
Merged, will go in v0.5.4 |
Summary
This PR resolves pending
// TODO: use with_capacity herecomments insmartcore::ensembleby pre-allocating memory capacities for tree vectors and sample tracking buffers based onparameters.n_trees.Key Changes:
src/ensemble/base_forest_regressor.rs:Vec::new()withVec::with_capacity(n_trees)fortreescontainer during forest regressor fitting.maybe_all_sampleswithVec::with_capacity(n_trees)whenparameters.keep_samplesis active.src/ensemble/random_forest_classifier.rs:treeswithVec::with_capacity(n_trees)forRandomForestClassifier.maybe_all_sampleswithVec::with_capacity(n_trees).Benefits:
Verification:
All unit tests, integration tests, and benchmarks pass clean (
cargo test --all-features).