Skip to content
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

[Google Blockly] sort blocks and skip childBlocks before comparing xml/json block arrays #51952

Merged
merged 4 commits into from
May 18, 2023

Conversation

mikeharv
Copy link
Contributor

@mikeharv mikeharv commented May 17, 2023

This updates the logging that was recently implemented for comparing blocks created from XML/JSON sources:

While the experiment ran this morning, we did end up logging some differences. Many of these differences seem to be false signals due to the blocks being in a different order in each list used for the comparison. It turns out that the function we call to get the blocks (getAllBlocks()) has an optional parameter that sorts the list based on the blocks position on the workspace. (Documentation: https://developers.google.com/blockly/reference/js/blockly.workspace_class.getallblocks_1_method)

I confirmed with the Blockly team that without this argument, the blocks are returned in an undefined order. Based on some spot-checking of logged projects, it seems like this could be happening most often with blocks that are close together on the workspace, but this is merely anecdotal and hypothetical. For example, the when hit an obstacle and when click blocks were not in the same order in each list for this workspace:
image

Separate from this issue, I also found some logged records that showed we were occasionally hitting a longer recursive loop when checking big stacks of blocks. This is because blocks stacked together have a childBlocks_ property that includes references to other blocks we'd already be checking. Adding this property to keysToSkip should make the test run more efficiently as we can skip comparing the same blocks multiple times.

With these changes, it's possible there could still be other differences logged the next time we run the experiment, but removing the common red herrings I saw today should help us narrow in on any actual issues that may exist.

Links

Testing story

Deployment strategy

Follow-up work

Privacy

Security

Caching

PR Checklist:

  • Tests provide adequate coverage
  • Privacy and Security impacts have been assessed
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

@mikeharv mikeharv changed the title sort blocks and skip childBlocks [Google Blockly] sort blocks and skip childBlocks before comparing xml/json block arrays May 17, 2023
@mikeharv mikeharv requested review from fisher-alice and a team May 17, 2023 20:59

// compareBlockArrays returns an array of differences found.
const differences = compareBlockArrays(xmlBlocks, jsonBlocks);
if (differences.length > 0 || experimentEnabled) {
// Log a record to Firehose/Redshift.
const recordData = {
projectUrl: dashboard.project.getShareUrl(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove projectURL?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When looking at the RedShift data, I realized that the url is already included under the device column that we automatically collect. It's also a better url than the project share link because it includes things like /view or /edit or tells us if they were viewing a curriculum level and not in a standalone project. Was just going to add a note to explain!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool - thanks!

Copy link
Contributor

@fisher-alice fisher-alice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank goodness that optional parameter is available!

@mikeharv
Copy link
Contributor Author

After discussing this with Maribeth, neither of us were confident enough that getAllBlocks() will actually return them in a consistent order because:

  • Blockly can sort based on the x/y coordinates of the blocks
  • We are using a non svg workspace so the blocks aren't actually rendered
  • There's a chance we could have blocks where x/y values are intentionally not serialized (e.g. event blocks in Flappy)

To be extra on the safe side, I've added a simple manual sort function will sort all blocks in each array alphabetically be block id. We don't care what order they're in really, as long as it's the same in each list. :)

FYI @bencodeorg @fisher-alice LMK if you have any questions/concerns since I'm not planning to merge tonight.

@fisher-alice
Copy link
Contributor

After discussing this with Maribeth, neither of us were confident enough that getAllBlocks() will actually return them in a consistent order because:

  • Blockly can sort based on the x/y coordinates of the blocks
  • We are using a non svg workspace so the blocks aren't actually rendered
  • There's a chance we could have blocks where x/y values are intentionally not serialized (e.g. event blocks in Flappy)

To be extra on the safe side, I've added a simple manual sort function will sort all blocks in each array alphabetically be block id. We don't care what order they're in really, as long as it's the same in each list. :)

FYI @bencodeorg @fisher-alice LMK if you have any questions/concerns since I'm not planning to merge tonight.

Sounds good - thanks for the update! I was curious about the ordering of the block arrays from the get go.

@mikeharv mikeharv merged commit d8523a6 into staging May 18, 2023
2 checks passed
@mikeharv mikeharv deleted the mike/update-block-comparison-test branch May 18, 2023 17:55
pablo-code-org pushed a commit that referenced this pull request May 25, 2023
…l/json block arrays (#51952)

* sort blocks and skip childBlocks

* stop logging project url, and move differences to front of record

* manually sort by block id just to be safe

* dispose temporary workspaces
snickell pushed a commit that referenced this pull request Feb 3, 2024
…l/json block arrays (#51952)

* sort blocks and skip childBlocks

* stop logging project url, and move differences to front of record

* manually sort by block id just to be safe

* dispose temporary workspaces
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants