We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Summary
This test code proves that DataValue has memory size 64 bytes, because DataValue is an enum struct which uses the maximum memory in each enum.
println!("memory size -> {:?}", std::mem::size_of::<DataValue>()); // 64 println!("memory size -> {:?}", std::mem::size_of::<Option<u64>>()); // 16
We should introduce a generic state implementation to improve memory and efficiency.
The text was updated successfully, but these errors were encountered:
Example for aggregate sum state.
struct AggregateSumState<T> { pub value: Option<T>, } impl<'a, T> GetState<'a, AggregateSumState<T>> for AggregateSumState<T> {} impl<T> AggregateSumState<T> where T: std::ops::Add<Output = T> + Clone + Copy + serde::Serialize + serde::de::DeserializeOwned { #[inline(always)] fn add(&mut self, other: &Option<T>) { match (&self.value, other) { (Some(a), Some(b)) => self.value = Some(a.add(*b)), (None, c) => self.value = c.clone(), _ => {} } } #[inline(always)] fn merge(&mut self, other: &Self) { match (&self.value, &other.value) { (Some(a), Some(b)) => self.value = Some(a.add(*b)), (None, c) => self.value = c.clone(), _ => {} } } pub fn serialize(&self, writer: &mut Vec<u8>) -> Result<()> { serde_json::to_writer(writer, &self.value)?; Ok(()) } pub fn deserialize<R: std::io::Read>(&mut self, reader: R) -> Result<()> { self.value = serde_json::from_reader(reader)?; Ok(()) } }
Sorry, something went wrong.
sundy-li
Successfully merging a pull request may close this issue.
Summary
This test code proves that DataValue has memory size 64 bytes, because DataValue is an enum struct which uses the maximum memory in each enum.
We should introduce a generic state implementation to improve memory and efficiency.
The text was updated successfully, but these errors were encountered: