mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-20 11:28:30 +08:00
Store document node inputs in Arc to reduce memory consumption (#3086)
Store values in memo hash contanier in arc
This commit is contained in:
@@ -156,10 +156,10 @@ pub mod monitor {
|
||||
pub const IDENTIFIER: crate::ProtoNodeIdentifier = crate::ProtoNodeIdentifier::new("graphene_core::memo::MonitorNode");
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
|
||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
|
||||
pub struct MemoHash<T: Hash> {
|
||||
hash: u64,
|
||||
value: T,
|
||||
value: Arc<T>,
|
||||
}
|
||||
|
||||
impl<'de, T: serde::Deserialize<'de> + Hash> serde::Deserialize<'de> for MemoHash<T> {
|
||||
@@ -183,10 +183,10 @@ impl<T: Hash + serde::Serialize> serde::Serialize for MemoHash<T> {
|
||||
impl<T: Hash> MemoHash<T> {
|
||||
pub fn new(value: T) -> Self {
|
||||
let hash = Self::calc_hash(&value);
|
||||
Self { hash, value }
|
||||
Self { hash, value: value.into() }
|
||||
}
|
||||
pub fn new_with_hash(value: T, hash: u64) -> Self {
|
||||
Self { hash, value }
|
||||
Self { hash, value: value.into() }
|
||||
}
|
||||
|
||||
fn calc_hash(data: &T) -> u64 {
|
||||
@@ -198,7 +198,7 @@ impl<T: Hash> MemoHash<T> {
|
||||
pub fn inner_mut(&mut self) -> MemoHashGuard<'_, T> {
|
||||
MemoHashGuard { inner: self }
|
||||
}
|
||||
pub fn into_inner(self) -> T {
|
||||
pub fn into_inner(self) -> Arc<T> {
|
||||
self.value
|
||||
}
|
||||
pub fn hash_code(&self) -> u64 {
|
||||
@@ -244,8 +244,8 @@ impl<T: Hash> Deref for MemoHashGuard<'_, T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Hash> std::ops::DerefMut for MemoHashGuard<'_, T> {
|
||||
impl<T: Hash + Clone> std::ops::DerefMut for MemoHashGuard<'_, T> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.inner.value
|
||||
Arc::make_mut(&mut self.inner.value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -392,7 +392,8 @@ impl<'input> Node<'input, DAny<'input>> for UpcastNode {
|
||||
type Output = FutureAny<'input>;
|
||||
|
||||
fn eval(&'input self, _: DAny<'input>) -> Self::Output {
|
||||
Box::pin(async move { self.value.clone().into_inner().to_dynany() })
|
||||
let memo_clone = MemoHash::clone(&self.value);
|
||||
Box::pin(async move { memo_clone.into_inner().as_ref().clone().to_dynany() })
|
||||
}
|
||||
}
|
||||
impl UpcastNode {
|
||||
|
||||
Reference in New Issue
Block a user