perf!: remove bound-caching from Type, do in SumType::General instead#3022
perf!: remove bound-caching from Type, do in SumType::General instead#3022
Conversation
Merging this PR will improve performance by 17.69%
Performance Changes
Comparing Footnotes
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3022 +/- ##
=======================================
Coverage 81.09% 81.09%
=======================================
Files 241 241
Lines 45054 45060 +6
Branches 38822 38828 +6
=======================================
+ Hits 36536 36541 +5
Misses 6542 6542
- Partials 1976 1977 +1
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:
|
| SumType::General(general) => { | ||
| let changed = general.rows.transform(tr)?; | ||
| if changed { | ||
| *general = GeneralSum::new(std::mem::take(&mut general.rows)); |
There was a problem hiding this comment.
Does this need a comment to say, recompute the bound?
|
This PR contains breaking changes to the public Rust API. cargo-semver-checks summary |
4ceb59e to
2dec804
Compare
2dec804 to
b45e61f
Compare
| &self.rows | ||
| } | ||
|
|
||
| pub(crate) fn rows_mut(&mut self) -> &mut [TypeRowRV] { |
There was a problem hiding this comment.
Note this allows bypassing the update of the bound, so we keep it crate-private (and use it only for things where we are sure the bound doesn't change - namely, extension resolution)
| /// [TypeDef]: crate::extension::TypeDef | ||
| pub(crate) fn validate(&self, var_decls: &[TypeParam]) -> Result<(), SignatureError> { | ||
| self.0.validate(var_decls)?; | ||
| // ALAN even this should be only a debug-assert really: |
There was a problem hiding this comment.
This temporary debris from #2895 has now moved to a proper home in Term::validate
Typecurrently caches theTypeBoundalongside its Term; there are only three possible Term:: variants, and the cache is pretty much redundant in two (and a half):Hence, make SumType::General store a
struct GeneralSum, with bound and rows (these are kept private to avoid mutating rows without updating the bound). And remove the cache in Type.BREAKING CHANGE: any match on
SumType::General {rows} ...rows...becomesSumType::General(gs) ...gs.rows()...; construct GeneralSum with ::new