-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Block serialization compression #1031
New issue
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
Block serialization compression #1031
Conversation
… shadow if they are the same, reduce duplication of information.
…a WIP since we don't deserialize blocks serialized in this way.
…st' block if trying to add to a list that is already at the limit.
… in a target that has been 'flattened' via JSON.stringify.
…the default project in gui.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really good. Thanks for documenting this so thoroughly. 👍
Out of curiosity's sake, what's the purpose of limiting a list to 200k items? Sure, that's an absurdly huge amount that I doubt will ever cause issues! But I'm curious anyways. Were gigantic lists causing problems? |
@towerofnix That's a good question! In 3.0, we are changing the way we store projects on the server to allow bigger projects. There are currently some projects in 2.0 that have very long lists (some for games, but others just to test the limits of a project's size). We want to continue to support these projects, but given that we'll be able to save and load much bigger projects in the future, we don't want to also allow even bigger lists because this will increase browser memory usage while attempting to run one of these projects (or display a monitor for these lists, or scroll through the blocks flyout, etc.). Ultimately, this would cause more browser crashes, which we want to avoid. We're hoping that a 200k limit is a good balance where most projects that currently use large lists (games, etc.) still run well, but we're not actively giving way to crashing more user's browsers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great overall, thanks for all the explanatory comments!
src/serialization/sb3.js
Outdated
obj.opcode = block.opcode; | ||
// NOTE: this is extremely important to serialize even if null; | ||
// not serializing `next: null` results in strange behavior |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
src/serialization/sb3.js
Outdated
obj.topLevel = block.topLevel ? block.topLevel : false; | ||
obj.shadow = block.shadow; | ||
obj.shadow = block.shadow; // I think we don't need this either.. |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
src/serialization/sb3.js
Outdated
} | ||
}; | ||
primitiveObj.topLevel = false; | ||
// what should we do about shadows |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
src/sprites/rendered-target.js
Outdated
'ON-FLIPPED': 'on-flipped' | ||
OFF: 'off', | ||
ON: 'on', | ||
ON_FLIPPED: 'on_flipped' |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
assetType = storage.AssetType.ImageVector; | ||
} else if (costumeFormat === 'png') { | ||
dataFormat = storage.DataFormat.PNG; | ||
} else if (['png', 'bmp', 'jpeg', 'jpg', 'gif'].indexOf(costumeFormat) >= 0) { |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
@@ -1,13 +1,15 @@ | |||
/** | |||
* @fileoverview | |||
* Partial implementation of a SB3 serializer and deserializer. Parses provided | |||
* An SB3 serializer and deserializer. Parses provided |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
obj.inputs = block.inputs; | ||
obj.fields = block.fields; | ||
obj.inputs = serializeInputs(block.inputs); | ||
obj.fields = serializeFields(block.fields); | ||
obj.topLevel = block.topLevel ? block.topLevel : false; | ||
obj.shadow = block.shadow; |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
@@ -69,17 +306,22 @@ const serializeCostume = function (costume) { | |||
// but that change should be made carefully since it is very | |||
// pervasive | |||
obj.md5ext = costume.md5; | |||
obj.dataFormat = costume.dataFormat; | |||
obj.dataFormat = costume.dataFormat.toLowerCase(); |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
…udio engine present. This is analagous to costumes getting loaded even if there is no renderer present.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 to the sound change, too!
My problem with this is that my only way past this limit, which I need for like a video playback thing is to use a method that combines multiple lists, which is harder to manage and expand. So either way, it will crash the browser, so I think lists should still be given infinite length or at least be given an option to do so. |
@Honyant, this pull request was merged almost a year ago, so any new conversation on here will not be easy to track. Please feel free to create an issue for your request. |
Resolves
#194
Proposed Changes
This is the last of the save/load work. This pull request covers the following changes:
number representing opcode
,info about the opcode
,(in one or more elements)
]:math_number
math_positive_number
math_whole_number
math_angle
math_integer
colour_picker
text
event_broadcast_menu
(this is the shadow block used in broadcast menus)data_variable
data_listcontents
id
-uid pair in the blocks, which were previously stored as:tempo
,volume
, and video related stateNote: Monitor serialization/deserialization is not covered by this work.
Reason for Changes
Making serialized 3.0 format smaller.
Test Coverage
Existing save/load tests pass. New test cases for the 3.0 format to be added in the near future.
Related PRs
scratchfoundation/scratch-parser#32
scratchfoundation/scratch-gui#1738