Reduce history system's excessive memory usage from storing copies of images each step (#845)

* Limit saved undo history

* Do not commit path every mouse move event

* Reference count images in history system instead of cloning the image data

* Increase history storage step limit to 100

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
0HyperCube
2022-11-11 11:44:43 -08:00
committed by GitHub
co-authored by Keavon Chambers
parent be353878d0
commit 4cda84521f
10 changed files with 39 additions and 23 deletions
+3
View File
@@ -583,6 +583,7 @@ impl Document {
image_data,
mime,
} => {
let image_data = std::rc::Rc::new(image_data);
let layer = Layer::new(LayerDataType::Image(ImageLayer::new(mime, image_data)), transform);
self.set_layer(&path, layer, insert_index)?;
@@ -606,6 +607,7 @@ impl Document {
Operation::SetNodeGraphFrameImageData { layer_path, image_data } => {
let layer = self.layer_mut(&layer_path).expect("Setting NodeGraphFrame image data for invalid layer");
if let LayerDataType::NodeGraphFrame(node_graph_frame) = &mut layer.data {
let image_data = std::rc::Rc::new(image_data);
node_graph_frame.image_data = Some(crate::layers::nodegraph_layer::ImageData { image_data });
} else {
panic!("Incorrectly trying to set image data for a layer that is not an NodeGraphFrame layer type");
@@ -831,6 +833,7 @@ impl Document {
Operation::ImaginateSetImageData { layer_path, image_data } => {
let layer = self.layer_mut(&layer_path).expect("Setting Imaginate image data for invalid layer");
if let LayerDataType::Imaginate(imaginate) = &mut layer.data {
let image_data = std::rc::Rc::new(image_data);
imaginate.image_data = Some(ImaginateImageData { image_data });
} else {
panic!("Incorrectly trying to set image data for a layer that is not an Imaginate layer type");