Skip to content

Conversation

@cwillisf
Copy link
Contributor

@cwillisf cwillisf commented Dec 4, 2025

Resolves

Supports an upcoming scratch-storage change that will resolve scratchfoundation/scratch-gui#7111 and POD-238

Proposed Changes

Main change: in task-herder, add QueueManager, a way to conveniently manage multiple throttling queues.

Supporting changes:

  • Add tests for the new QueueManager
  • Fix and simplify the concurrency logic in TaskQueue
  • Support vendor chunks in scratch-storage, which helps when using npm link scratch-storage
  • Add {willReadFrequently: true} to the Canvas.getContext('2d') call in the bitmap load path

Reason for Changes

  • The upcoming scratch-storage change will use this new QueueManager to manage per-host throttling queues.
  • The previous concurrency logic didn't provide back pressure from the concurrency limiter
    • Without that back pressure, the client needs to make extra effort to avoid growing the queue unbounded.
    • It's also not consistent with the rate-limiting behavior.
    • Removing the p-limit dependency is a nice side effect. (There's nothing wrong with p-limit, but fewer dependencies is better.)
  • The willReadFrequently change:
    • Matches our actual intent with the canvas/context
    • Fixes a Chrome console warning
    • Fixes a Chrome bug(?) that corrupted buffers when the asset download allowed concurrency > 5
    • Might improve performance

Test Coverage

The new QueueManager is covered by new tests. Existing tests cover everything else.

@cwillisf cwillisf requested a review from a team as a code owner December 4, 2025 18:04
@cwillisf cwillisf requested review from Copilot and removed request for a team December 4, 2025 18:06
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a QueueManager class to manage multiple throttling queues and refactors TaskQueue to remove the p-limit dependency by implementing custom concurrency control. The changes also optimize canvas operations by adding willReadFrequently: true to 2D context creation.

  • Introduces QueueManager for convenient management of multiple per-host throttling queues
  • Refactors TaskQueue concurrency logic to provide proper back pressure and remove external dependency
  • Adds canvas optimization flags to fix Chrome warnings and potential buffer corruption

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/task-herder/src/QueueManager.ts New class for managing multiple named task queues with shared/individual configurations
packages/task-herder/test/manager.test.ts Comprehensive test coverage for QueueManager API including create, get, and getOrCreate methods
packages/task-herder/src/index.ts Exports the new QueueManager class
packages/task-herder/src/TaskQueue.ts Refactored concurrency control with custom implementation, removed p-limit dependency, added options getter
packages/task-herder/package.json Removed p-limit dependency
package-lock.json Removed p-limit and yocto-queue dependencies from task-herder
packages/scratch-vm/src/import/load-costume.js Added willReadFrequently flag to canvas 2D context for bitmap loading
packages/scratch-render/src/BitmapSkin.js Added willReadFrequently flag with explanatory comment for WebGL texture data extraction
packages/scratch-gui/webpack.config.js Added vendor chunks copying for scratch-storage npm link support

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 4, 2025

Test report for scratch-svg-renderer

  1 files  ±0   60 suites  ±0   0s ⏱️ ±0s
124 tests ±0  124 ✅ ±0  0 💤 ±0  0 ❌ ±0 
276 runs  ±0  275 ✅ ±0  1 💤 ±0  0 ❌ ±0 

Results for commit 6082f36. ± Comparison against base commit 7105939.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 4, 2025

Test report for task-herder

28 tests  +14   28 ✅ +14   0s ⏱️ ±0s
 7 suites + 1    0 💤 ± 0 
 1 files   ± 0    0 ❌ ± 0 

Results for commit 6082f36. ± Comparison against base commit 7105939.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 4, 2025

Test report for scratch-render

  1 files  ±0   55 suites  ±0   3s ⏱️ -1s
209 tests ±0  209 ✅ ±0  0 💤 ±0  0 ❌ ±0 
279 runs  ±0  279 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit 6082f36. ± Comparison against base commit 7105939.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 4, 2025

Test report for scratch-vm

    1 files  ±0    763 suites  ±0   1m 5s ⏱️ -1s
1 666 tests ±0  1 666 ✅ ±0   0 💤 ±0  0 ❌ ±0 
4 855 runs  ±0  4 825 ✅ ±0  30 💤 ±0  0 ❌ ±0 

Results for commit 6082f36. ± Comparison against base commit 7105939.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 4, 2025

Test report for scratch-gui

  2 files  ±0   62 suites  ±0   10m 37s ⏱️ + 1m 37s
398 tests ±0  390 ✅ ±0  8 💤 ±0  0 ❌ ±0 
416 runs  ±0  408 ✅ ±0  8 💤 ±0  0 ❌ ±0 

Results for commit 6082f36. ± Comparison against base commit 7105939.

♻️ This comment has been updated with latest results.

This fixes a Chrome crash when loading assets with moderately high
concurrency. It's also allegedly a good idea for performance.
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.

CE-132 Loading a project with many assets can fail

2 participants