From dea7cc23e3378712937e133cb5ebeeb32c6a22bd Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 10 Jan 2017 15:55:36 -0700 Subject: [PATCH] Disable periodic serialization for buffers > 2MB Writing so much data to IndexedDB is blocking the main thread for perceptible amounts of time. A patch-based representation of the modified state could allows us to pay only for what has changed, but is too complex to justify implementing right now to support full crash recovery for large files. Signed-off-by: Max Brunsfeld --- src/project.coffee | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/project.coffee b/src/project.coffee index 91ecfee38..522fbfbc7 100644 --- a/src/project.coffee +++ b/src/project.coffee @@ -70,7 +70,15 @@ class Project extends Model serialize: (options={}) -> deserializer: 'Project' paths: @getPaths() - buffers: _.compact(@buffers.map (buffer) -> buffer.serialize({markerLayers: options.isUnloading is true}) if buffer.isRetained()) + buffers: _.compact(@buffers.map (buffer) -> + if buffer.isRetained() + state = buffer.serialize({markerLayers: options.isUnloading is true}) + # Skip saving large buffer text unless unloading to avoid blocking main thread + if not options.isUnloading and state.text.length > 2 * 1024 * 1024 + delete state.text + delete state.digestWhenLastPersisted + state + ) ### Section: Event Subscription