Skip to content

Optimize transferables duplicate detection with Set for O(1) lookups#74635

Merged
adamsilverstein merged 2 commits into
feature/74352-new-wordpress-vips-package-no-shopifyfrom
copilot/sub-pr-74629
Jan 15, 2026
Merged

Optimize transferables duplicate detection with Set for O(1) lookups#74635
adamsilverstein merged 2 commits into
feature/74352-new-wordpress-vips-package-no-shopifyfrom
copilot/sub-pr-74629

Conversation

Copilot AI commented Jan 15, 2026

Copy link
Copy Markdown
Contributor

The findTransferables function used .includes() for duplicate detection, resulting in O(n²) complexity when processing many transferable objects.

Changes

  • Added transferableSet for O(1) duplicate lookups alongside the result array
  • Replaced 8 .includes() calls with .has() checks on lines 24, 36, 48, 60, 72, 84, 96, and 114
  • Reduced overall complexity from O(n²) to O(n)

Example

// Before: O(n) lookup per transferable
if (!transferables.includes(obj)) {
    transferables.push(obj);
}

// After: O(1) lookup per transferable  
if (!transferableSet.has(obj)) {
    transferableSet.add(obj);
    transferables.push(obj);
}

Behavior remains identical. Performance improvement is most significant when transferring large numbers of ArrayBuffers, TypedArrays, or other transferable objects in worker messages.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: adamsilverstein <2676022+adamsilverstein@users.noreply.github.com>

Copilot AI commented Jan 15, 2026

Copy link
Copy Markdown
Contributor Author

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • translate.wordpress.org
    • Triggering command: /usr/local/bin/node node i18n-cache/index.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] WIP address feedback on adding @wordpress/worker-threads package migration Optimize transferables duplicate detection with Set for O(1) lookups Jan 15, 2026
Copilot AI requested a review from adamsilverstein January 15, 2026 01:04
@adamsilverstein adamsilverstein marked this pull request as ready for review January 15, 2026 03:27
@github-actions

Copy link
Copy Markdown

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: .

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @Copilot.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: Copilot.

Co-authored-by: adamsilverstein <adamsilverstein@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@adamsilverstein adamsilverstein merged commit 2bc9089 into feature/74352-new-wordpress-vips-package-no-shopify Jan 15, 2026
30 of 37 checks passed
@adamsilverstein adamsilverstein deleted the copilot/sub-pr-74629 branch January 15, 2026 03:29
adamsilverstein added a commit that referenced this pull request Jan 20, 2026
…74635)

* Initial plan

* Optimize transferables duplicate detection using Set

Co-authored-by: adamsilverstein <2676022+adamsilverstein@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: adamsilverstein <2676022+adamsilverstein@users.noreply.github.com>
adamsilverstein added a commit that referenced this pull request Feb 2, 2026
…74635)

* Initial plan

* Optimize transferables duplicate detection using Set

Co-authored-by: adamsilverstein <2676022+adamsilverstein@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: adamsilverstein <2676022+adamsilverstein@users.noreply.github.com>
adamsilverstein added a commit to adamsilverstein/gutenberg that referenced this pull request Feb 24, 2026
…ordPress#74635)

* Initial plan

* Optimize transferables duplicate detection using Set

Co-authored-by: adamsilverstein <2676022+adamsilverstein@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: adamsilverstein <2676022+adamsilverstein@users.noreply.github.com>
adamsilverstein added a commit to adamsilverstein/gutenberg that referenced this pull request Feb 24, 2026
…ordPress#74635)

* Initial plan

* Optimize transferables duplicate detection using Set

Co-authored-by: adamsilverstein <2676022+adamsilverstein@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: adamsilverstein <2676022+adamsilverstein@users.noreply.github.com>
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.

2 participants