Optimize table-like length storage#172
Conversation
sasial-dev
left a comment
There was a problem hiding this comment.
Thank you for the idea - but I think we need to reconsider how it's actually executed.
I'm not a big fan of resolve_ty/ variants_size personally - resolving tydecls based upon going back to the config so many times over feels stupid! I also don't want to pass the whole config to irgen.
One idea I had - maybe we should consider adding a length argument to the ty? Then we can assign it in convert.rs or whatever.
Otherwise, let me know if you have any other ideas on how we should approach this.
I know this would sorta backpedal and require a refactor of your work on #166, but I think it's for the best.
| pub fn variants_size(&self) -> Option<NumTy> { | ||
| match self { | ||
| Ty::Enum(Enum::Unit(variants)) => Some(NumTy::from_f64(0.0, (variants.len() - 1) as f64)), | ||
| Ty::Enum(Enum::Tagged { variants, .. }) => Some(NumTy::from_f64(0.0, (variants.len() - 1) as f64)), | ||
| Ty::Num(numty, ..) => match numty { | ||
| NumTy::F32 => None, | ||
| NumTy::F64 => None, | ||
| NumTy::U8 => Some(NumTy::U8), | ||
| NumTy::U16 => Some(NumTy::U16), | ||
| NumTy::U32 => None, | ||
| NumTy::I8 => Some(NumTy::U8), | ||
| NumTy::I16 => Some(NumTy::U16), | ||
| NumTy::I32 => None, | ||
| }, | ||
| _ => None, | ||
| } | ||
| } |
There was a problem hiding this comment.
This function is really weird.
|
I removed the number optimization since the formula for the length of a map is actually |
|
I wonder if we can (or should!) make our optimisations more aggressive? e.g. length should only be stored in a |
|
I've been looking into making the NumTy algorithm smarter like that, but I think it's better if it becomes a separate PR. |
sasial-dev
left a comment
There was a problem hiding this comment.
Thank you!
This lays the groundwork nicely for further optimisations.
Optimizes length storage for table-like types (map, set). It works by getting the amount of possible keys (number of variants for enums) to use for the length storage.