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 <maxbrunsfeld@github.com>
This commit is contained in:
Nathan Sobo
2017-01-10 15:55:36 -07:00
committed by Max Brunsfeld
parent fb7e25ece6
commit dea7cc23e3

View File

@@ -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